13,295,178 members (69,878 online)
Rate this:
See more:
Hi,

Let me know how can i insert fractions into database.

ex - ½ ¼ 1/3 5/3 7/3 etc..
Posted 19-Apr-11 3:33am

Rate this:

Solution 1

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.
v2
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.
Marcus Kramer 19-Apr-11 9:40am

3/5 = .6 ???? Simple mathematics.

Simple for *many* people. I wouldn't even claim MOST people could do that math with the sad state of education nowadays.
Rate this:

Solution 2

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
v2
Henry Minute 19-Apr-11 8:58am

I was about to post something similar. +5
Rajeshwar Code- Developer 19-Apr-11 8:59am

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.
Marcus Kramer 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"..

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 90 Richard Deeming 70 F-ES Sitecore 70 _duDE 65 OriginalGriff 65
 OriginalGriff 2,131 Jochen Arndt 1,180 Richard MacCutchan 1,090 ppolymorphe 917 Dave Kreskowiak 915