# Formatting decimal numbers to fractions

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

## Recommended Posts

I have a question about formatting numbers.

Is there a way to format a number such that if it is not a whole integer it will display as

a number plus a fractional remainder?

To complicate this further, I would like to constrain the fractional result to eighths (1/8) or sixteenths (1/16).

For example: 1.625 would show up as (1-5/8) and 1.685 would show up as (1-11/16).

If the fractional result was other than an eighth or a sixteenth I would like to have the number round to those type of fractions.

If anybody could help me here I would sure appreciate it.

Thanks,

Jarvis

##### Share on other sites

I have a question about formatting numbers.

Is there a way to format a number such that if it is not a whole integer it will display as

a number plus a fractional remainder?

To complicate this further, I would like to constrain the fractional result to eighths (1/8) or sixteenths (1/16).

For example: 1.625 would show up as (1-5/8) and 1.685 would show up as (1-11/16).

If the fractional result was other than an eighth or a sixteenth I would like to have the number round to those type of fractions.

If anybody could help me here I would sure appreciate it.

Thanks,

Jarvis

##### Share on other sites

I hope this is correct:

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 ; 2 ) ;

sixteenths / 2 & "/8" ;

sixteenths & "/16" )

)

)

##### Share on other sites

I hope this is correct:

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 ; 2 ) ;

sixteenths / 2 & "/8" ;

sixteenths & "/16" )

)

)

##### Share on other sites

Comment,

The code you recommended does a good job of parsing the decimal into itself + it's fractions

but it needs a little more embellishment.

for example:

7.3125 shows up as 7516 which is what I asked for

But if possible..... could you tell me how to make this read 7 5/16

I need a space between the 7 & 5 and a / between 5 & 16.

If I was a little smarter I could probably stare at your code and figure this out.

But I'm not and you are.

Any more suggestions?

Thanks,

Jarvis

##### Share on other sites

Comment,

The code you recommended does a good job of parsing the decimal into itself + it's fractions

but it needs a little more embellishment.

for example:

7.3125 shows up as 7516 which is what I asked for

But if possible..... could you tell me how to make this read 7 5/16

I need a space between the 7 & 5 and a / between 5 & 16.

If I was a little smarter I could probably stare at your code and figure this out.

But I'm not and you are.

Any more suggestions?

Thanks,

Jarvis

##### Share on other sites

1. Is your calculation defined to return a TEXT result?

2. If you want a space, instead of - , replace the "-" in the formula with " " (that's a space surrounded by quotes).

##### Share on other sites

1. Is your calculation defined to return a TEXT result?

2. If you want a space, instead of - , replace the "-" in the formula with " " (that's a space surrounded by quotes).

##### Share on other sites

Comment,

You were right. My calculation was not set up to result in text. When I changed that part everything worked.

Except for the part where I neglected to allow for quarters (1/4 & 3/4) as a possible end result.

Where would I stick this in the equation?

Jarvis

##### Share on other sites

Comment,

You were right. My calculation was not set up to result in text. When I changed that part everything worked.

Except for the part where I neglected to allow for quarters (1/4 & 3/4) as a possible end result.

Where would I stick this in the equation?

Jarvis

##### Share on other sites

You keep changing the specs. Earlier you said "I would like to constrain the fractional result to eighths (1/8) or sixteenths (1/16)".

It's not that I am complaining. Well, I am, but the point is - when you make something for a specific purpose, then adapt it, it may end up being less efficient than making it for a general purpose to begin with. So, with this caveat, try:

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" )

)

)

##### Share on other sites

You keep changing the specs. Earlier you said "I would like to constrain the fractional result to eighths (1/8) or sixteenths (1/16)".

It's not that I am complaining. Well, I am, but the point is - when you make something for a specific purpose, then adapt it, it may end up being less efficient than making it for a general purpose to begin with. So, with this caveat, try:

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" )

)

)

##### Share on other sites

Thanks Comment!

It works perfect!

Jarvis

##### Share on other sites

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

## Create an account

Register a new account