Search code examples
formattingroundingf-script

How to round number to 2 decimals


on my way to help a fellow I wrote a simple F-Script without even knowing the existing of such language

http://forums.marketcircle.com/eve/forums/a/tpc/f/2931083693/m/883106236

but I tried to find a way to round the number to 2 decimal places and I found nothing.

Can someone help me out that to finalize my help? Thank you.

The script is:

"Get amount to use from API"
amountEur := element valueForKeyPath:'parent.reportData.object.subtotalPlusMarkupMinusDiscount'.

"Let's convert to EEK"
amountEEK := amountEur / 15.6466.

"Return the value"
amountEEK.

working script after answer

"Get amount to use from API"
amountEur := element valueForKeyPath:'parent.reportData.object.subtotalPlusMarkupMinusDiscount'.

"Let's convert to EEK"
amountEEK := amountEur / 15.6466.

"Floor it"
floorEEK := ((amountEEK * 100) + 0.5) floor.

"Return the value"
floorEEK / 100.

Solution

  • If there's not a native round function then this should work:

    Multipy by 100, floor, divide by 100.