Click here to Skip to main content
11,931,104 members (58,383 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET

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
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.
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: bad
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,

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 , 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"..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 19 Apr 2011
Copyright © CodeProject, 1999-2015
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