Jump to content
Server Maintenance This Week. ×

Convert decimals to fractions


This topic is 5979 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I am a woodworker trying to make a cutlist for a project. I've been away from FM for a while, so sorry for the beginner-like question.

Using FM7, I'd like to enter data into a field as so (15 1/8) and have it stay that way. I'd, of course, like my calculations to work too!

As an added bonus is it possible to have the option to enter data as a decimal and let FM convert it for me (sometimes it's just easier to enter 15.75 but I don't always remember the decimal values for 1/8's & 1/16's)

A year ago, I probably would have known the answer, but I haven't entered "Layout Mode" in a while.

Thanks.

Bob

Link to comment
Share on other sites

Look here:

http://www.fmforums.com/forum/showtopic.php?tid/170725/post/179444/hl/fraction/fromsearch/1/#179444

Here slightly rewritten below to account for integers better, and put a Let wrapper around it.

Let([

integer=Int(number);

numerator=Mod(number;1)

];

Case(integer;integer &" ";"")&

Case(

Int(numerator*64) < 1;"";

Mod(Int(numerator*64);32) = 0; "1/2";

Mod(Int(numerator*64);16) = 0;Div(Int(numerator*64);16) & "/4";

Mod(Int(numerator*64);8) = 0; Div(Int(numerator*64);8) & "/8";

Mod(Int(numerator*64);4) = 0; Div(Int(numerator*64);4) & "/16";

Mod(Int(numerator*64);2) = 0; Div(Int(numerator*64);2) & "/32";

Int(numerator*64) & "/64")

)

Mikhail Edoshin ( http://edoshin.skeletonkey.com/calculating/index.html ) also has a more robust set of CFs that'll provide a more accurate fraction approximation...but it's less useful for woodworking, because it's hard to find 9/11ths on that tape measure...

On top of that, search for "fraction" here in the forums, it's come up before and various solutions offered.

hth

Colin

Edit: if you're really using FM7, you'll prob. want to use a variant of the original written code in the first link. Let [] won't work in 7.

Edited by Guest
added postscript re: FM7
Link to comment
Share on other sites

This topic comes up from time to time. I just did a search for [color:blue]+decimals +fractions and it turned up 5 or 6 hits. My reply to one of them mentions a couple of files at DatabasePros.com (link is above in Blue).

HTH

Lee

Link to comment
Share on other sites

Yes - though most of referenced solutions attempt to find the closest approximate fraction, which isn't the same as the closest "inch" fraction.

The poster's going to want 1/2, 1/4, 1/8, 1/16, 1/32, or 1/64...and if he's some kind of mastermind woodworker with microscopic power tools, 1/128 or, if he's superhuman, even 1/256.

7/10ths is a probably a more accurate representation of .69375, but it's less useful than 11/16ths for the purpose.

I only point it out because I had to resolve a similar situation (carpentry client) and had a heck of a time finding the solution I point out above on this forum. None of the others ended up being suitable.

Link to comment
Share on other sites

I'd like to enter data into a field as so (15 1/8) and have it stay that way. I'd, of course, like my calculations to work too!

You will need to enter your data into a text field. For conversion to decimal (to be used in calculations), you will need to be careful to enter data in a consistent manner.

To convert the text string into a decimal number, you could use something like:

Evaluate ( Substitute ( TextString ; " " ; "+" ) )

Since it seems you will be using only powers of two denominators (i.e. 2, 4, 8, 16, etc.), the conversion from decimal to fraction can be rather simple - see:

http://www.fmforums.com/forum/showtopic.php?tid/152662/

http://www.fmforums.com/forum/showtopic.php?tid/172462/

Let [] won't work in 7.

Of course it will.

Link to comment
Share on other sites

Thanks for the replies guys... After reading and experimenting with all of your answers (and links to other threads) I found a solution that works perfectly for my application (below).

The only thing that doesn't work is anything that should result in 1/2 shows up as 2/4. All others are correct 3/16, 5/8 etc.. are perfect. 2/4 is the only thing I can't get to result to 1/2.

Sorry for the stupidity. Obviously math isn't my best subject.

Here's the calc

--------------------

Let ( [

fraction = Mod ( Number ; 1 ) ;

sixteenths = Round ( fraction * 16 ; 0 )

] ;

Case ( Int ( Number ) ; Int ( Number) )

&

Case ( Int ( Number ) and sixteenths ; "-" )

&

Case (

sixteenths ; Choose ( Mod ( sixteenths ; 4 ) ;

sixteenths / 4 & "/4" ;

sixteenths & "/16" ;

sixteenths / 2 & "/8" ;

sixteenths & "/16" )

)

)

Thanks again.

Bob

Link to comment
Share on other sites

Colin wins the prize. :yay:

The interesting thing is that the US went decimal for currency (money) very early on: Australia only changed to decimal in 1966. Before that we had the British LSD. I think the UK went to decimal currency in the 1970s (I've got a proof set of the first UK decimal coins somewhere at home that I was given when I was ~10 years old).

Link to comment
Share on other sites

This topic is 5979 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.