tbfilemaker Posted February 13, 2007 Posted February 13, 2007 Greetings, I need to get the values on the left and right side of a decimal. I have the left side figured out via the truncate function, however, how do I get the value on the right side of the decimal? Left Side Calc=Truncate(TOTAL_COST, 0) Ride Side Calc= Any help would be greatly appreicated. Thanks in advance!
LaRetta Posted February 13, 2007 Posted February 13, 2007 (edited) Whole number = Int ( numberField ) decimal portion = Mod ( numberField , 1 ) UPDATE: If you want to drop the decimal, just add *100 at the end of the decimal portion. Of course these should be number fields. Edited February 13, 2007 by Guest Added update
comment Posted February 13, 2007 Posted February 13, 2007 If you want to drop the decimal, just add *100 at the end of the decimal portion. You've lost me there.
LaRetta Posted February 13, 2007 Posted February 13, 2007 I was unsure of the result required; whether it was to 'write out' the number or what. If the number is 1.22 and only 22 is requested then Mod ( numberField , 1 ) will produce .22 but Mod ( numberField , 1 ) * 100 will produce 22. There are other ways but that's what came to me quickly. :wink2:
tbfilemaker Posted February 13, 2007 Author Posted February 13, 2007 Thanks for the feedback, it turns out that there will only be two decimal values for my result so *100 will work just fine. Thanks again for this solution!
LaRetta Posted February 13, 2007 Posted February 13, 2007 (edited) You were right - I was in a hurry heading out the door. 3.1415926535897932 would break. I appreciate the catch! How about: Mod( Round( numberField , 2 ) , 1 ) * 100 It still lacks elegance ... Edited February 13, 2007 by Guest
Genx Posted February 13, 2007 Posted February 13, 2007 (edited) Could also use... Left( numberField ; Position( numberField ; "." ; 1 ; 1 ) - 1 ) ...but meh EDIT: Left( numberField , If( PatternCount( numberField , "." ) , Position( numberField , "." , 1 ; 1 ) - 1 , numberField ) ) Edited February 14, 2007 by Guest kind of long winded and definitley not recommended but it still works
LaRetta Posted February 13, 2007 Posted February 13, 2007 (edited) We're working on the remainder, Genx. That produces the integer. And they are on vs. 6 so switch the semi-colons. I prefer not to mix number and text functions if I can help it. I was looking for straight math. UPDATE: There are many fun ways to go here! I like these puppies! Edited February 13, 2007 by Guest
comment Posted February 13, 2007 Posted February 13, 2007 Depends on the purpose. If it's currency (as it seems to be in this case), that would work well to extract the (whole) cents portion of the amount - provided the amount is not negative. How about: Right ( Round ( number * 100 , 0 ) , 2 )
comment Posted February 13, 2007 Posted February 13, 2007 Left( numberField ; Position( numberField ; "." ; 1 ; 1 ) - 1 ) Try it with a whole number.
LaRetta Posted February 13, 2007 Posted February 13, 2007 (edited) Yep, I'd conceed mixing number and text functions if it's leaner and just as clear. Nice! Again, change the semi-colons to commas for vs. 6. I'm glad you mentioned the decimal length; that's the kind of omission which can bite us and something I should have thought of! Edited February 13, 2007 by Guest added "Nice!"
comment Posted February 13, 2007 Posted February 13, 2007 OK, no text functions: Mod ( Round ( Abs ( number * 100 ) , 0 ) , 100 )
LaRetta Posted February 13, 2007 Posted February 13, 2007 (edited) Thanks for the feedback, it turns out that there will only be two decimal values for my result so *100 will work just fine. Hold on! It isn't the result we're concerned with. If your number field has more than two decimals (and I'm not talking about what displays in Field Format), then my FIRST calc will break! Listen to Comment here. His is also more efficient! :wink2: Edited February 13, 2007 by Guest
LaRetta Posted February 13, 2007 Posted February 13, 2007 OK, no text functions: Mod ( Round ( Abs ( number * 100 ) , 0 ) , 100 ) What does that give us that this one doesn't, Michael? Mod( Round( numberField , 2 ) , 1 ) * 100 I can see no difference in my tests. Now this stuff brings a flush to my cheeks! I could play with these puppies all day!
comment Posted February 13, 2007 Posted February 13, 2007 It's the same thing, except the Abs(). IIRC, you don't need the Abs() in version 6, but it's better to plan ahead. BTW, if rounding, one should apply similar rounding before extracting the integer portion - otherwise 0.995 will return 0 on both.
Genx Posted February 13, 2007 Posted February 13, 2007 Hmmm, righto re the whole number thing. Heads not working to well as usual :)
LaRetta Posted February 13, 2007 Posted February 13, 2007 Good points. I see mine handles negatives as well. It is interesting to re-combine these functions and observe the subtle differences between them.
comment Posted February 13, 2007 Posted February 13, 2007 I see mine handles negatives as well. Not in v.7 and above.
LaRetta Posted February 13, 2007 Posted February 13, 2007 (edited) Yikes! I converted the vs. 6 to vs. 8 and my calc changed from -23 to 77!! Is this the Abs() piece? I must figure this out! IIRC, you don't need the Abs() in version 6, but it's better to plan ahead. Now your comment (smile) fits ... Edited February 13, 2007 by Guest
Recommended Posts
This topic is 6555 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