Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Let me know how can i insert fractions into database.

ex - ½ ¼ 1/3 5/3 7/3 etc..
Posted

You store them as either decimal or double types. I assume that you're passing these values as strings (because that's the only way you can represent a "fraction"), so you just have to parse the strings and do the math on them first.
 
Share this answer
 
v2
Comments
Rajeshwar Code- Developer 19-Apr-11 8:44am    
Thanks for reply, actually ex- there is 3/5 I want to convert this into fractions and insert into database. is there any possible.
fjdiewornncalwe 19-Apr-11 9:40am    
3/5 = .6 ???? Simple mathematics.
#realJSOP 19-Apr-11 9:43am    
Simple for *many* people. I wouldn't even claim MOST people could do that math with the sad state of education nowadays.
A simple fraction[^] can be defined by having a denominator and a numerator. To simplify things let both denominator and numerator be of biginteger and we will store a all our simple fractions in reduced form.

So to get started there will be a table that stores all simple fractions in reduced form:

biginteger id
biginteger denominator
biginteger numerator

Let id be an autoincrement PK and denominator and numerator form a unique index.

If you also want to have complex fractions you'll probably need to introduce expressions (as a tree).

Best Regards,

-MRB
 
Share this answer
 
v2
Comments
Henry Minute 19-Apr-11 8:58am    
I was about to post something similar. +5
Rajeshwar Code- Developer 19-Apr-11 8:59am    
Thanks for reply, let me tell you my task.

i ll get all mathematics questions in MS word
take one ex question - add two number 3/5 + 7/5 = ?......
so when i copy from ms word and paste into rich textbox into window vb.net , the format of question loose , how can fix this.
fjdiewornncalwe 19-Apr-11 9:39am    
Just what I was thinking. Another option is to simply have a transalation version where the fraction is stored and retrieved using a stored procedure translating a varchar column with a string representation of the fraction stored. i.e. "3/4"..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900