Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Juggernaut

Get value on right side of decimal?

Featured Replies

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!

Whole number = Int ( numberField )

decimal portion = Mod ( numberField , 1 )

:wink2:

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 by Guest
Added update

If you want to drop the decimal, just add *100 at the end of the decimal portion.

You've lost me there.

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:

And if the number is 3.1415926535897932 ?

  • 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!

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 by Guest

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 by Guest
kind of long winded and definitley not recommended but it still works

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. :wink2:

UPDATE: There are many fun ways to go here! I like these puppies!

Edited by Guest

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 )

Left( numberField ; Position( numberField ; "." ; 1 ; 1 ) - 1 )

Try it with a whole number.

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 by Guest
added "Nice!"

OK, no text functions:

Mod ( Round ( Abs ( number * 100 ) , 0 ) , 100 )

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 by Guest

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!

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.

Hmmm, righto re the whole number thing. Heads not working to well as usual :)

Good points. I see mine handles negatives as well. It is interesting to re-combine these functions and observe the subtle differences between them.

I see mine handles negatives as well.

Not in v.7 and above.

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 by Guest

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.