Forum Index

No notifications
Notifications

Favorites

No favorites found
Ask the community Need help to achieve something? - Ask the Community
Join the Conversation > Ask the community > Decimal places in a Variable View modes: 
User avatar
Advanced member
Advanced member
scot.jones - 22/12/2016 12:17:07
   
RE:Decimal places in a Variable

Hi Rikard,  thanks for your reply. 

That might work for me, however the my calculation variable will not always be a whole number so i'd need to differenciate somehow.

Does FormatNumber have a currency format?.  (its currency in my variable hense wanting the 2 decimal places)

 


User avatar
KnowledgeKube Staff
KnowledgeKube Staff
Rikard - 22/12/2016 11:40:19
   
RE:Decimal places in a Variable

Hi Scot :)

I believe what you're looking for is the FormatNumber function, which allows you to apply numeric formatting to an integer value. The following expression should do what you want:

CalculationResult:=FormatNumber(CalculationResult,"en-GB","{0:F}");

If you pass the result of your calculation into the CalculationResult variable, this expression will add two decimal places to its number value (if it doesn't already have them) and then pass it right back to the same variable.

The second argument defines the number culture, and the third argument defines the formatting you want to apply, which in this case is to add decimal points to the number. As written above this will add two decimal places by default, but if you want to change this amount you simply add the number of decimals you want after the "F", For example, if you want to add four decimal places, you would write it like this:

FormatNumber(CalculationResult,"en-GB","{0:F4}");

I hope that answers your question. If you're having any problems please don't hesitate to let me know. :)


User avatar
Advanced member
Advanced member
scot.jones - 22/12/2016 10:40:05
   
Decimal places in a Variable

Hi,

How would I ensure a variable that is a result of a calculation always has 2 decimal places in its result?  I would want the result for a whole number to be  213.00  not 213  

Thanks in advance.

 


1 2 3
RSS Feed