Jarvis Posted March 21, 2005 Author Posted March 21, 2005 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
Jarvis Posted March 21, 2005 Posted March 21, 2005 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
comment Posted March 21, 2005 Posted March 21, 2005 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" ) ) )
comment Posted March 21, 2005 Posted March 21, 2005 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" ) ) )
Jarvis Posted March 21, 2005 Author Posted March 21, 2005 Comment, Thanks for your help........so far. 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
Jarvis Posted March 21, 2005 Author Posted March 21, 2005 Comment, Thanks for your help........so far. 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
comment Posted March 21, 2005 Posted March 21, 2005 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).
comment Posted March 21, 2005 Posted March 21, 2005 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).
Jarvis Posted March 21, 2005 Author Posted March 21, 2005 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 PS: Thanks for your patience.
Jarvis Posted March 21, 2005 Author Posted March 21, 2005 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 PS: Thanks for your patience.
comment Posted March 21, 2005 Posted March 21, 2005 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" ) ) )
comment Posted March 21, 2005 Posted March 21, 2005 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" ) ) )
Recommended Posts
This topic is 7556 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 accountSign in
Already have an account? Sign in here.
Sign In Now