Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  
v2
Comments
Rajeshwar Code- Developer at 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 at 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: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
v2
Comments
Henry Minute at 19-Apr-11 8:58am
   
I was about to post something similar. +5
Rajeshwar Code- Developer at 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.
Marcus Kramer at 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)

  Print Answers RSS
0 OriginalGriff 245
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 19 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100