Jump to content

Get value on right side of decimal?


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

Recommended Posts

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!"
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This topic is 6274 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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