February 13, 200718 yr 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!
February 13, 200718 yr 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, 200718 yr by Guest Added update
February 13, 200718 yr If you want to drop the decimal, just add *100 at the end of the decimal portion. You've lost me there.
February 13, 200718 yr 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:
February 13, 200718 yr Author 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!
February 13, 200718 yr 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, 200718 yr by Guest
February 13, 200718 yr 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, 200718 yr by Guest kind of long winded and definitley not recommended but it still works
February 13, 200718 yr 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, 200718 yr by Guest
February 13, 200718 yr 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 )
February 13, 200718 yr Left( numberField ; Position( numberField ; "." ; 1 ; 1 ) - 1 ) Try it with a whole number.
February 13, 200718 yr 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, 200718 yr by Guest added "Nice!"
February 13, 200718 yr 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, 200718 yr by Guest
February 13, 200718 yr 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!
February 13, 200718 yr 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.
February 13, 200718 yr Good points. I see mine handles negatives as well. It is interesting to re-combine these functions and observe the subtle differences between them.
February 13, 200718 yr 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, 200718 yr by Guest
Create an account or sign in to comment