rapidpro / expressions

Expression parsing and evaluation support
BSD 3-Clause "New" or "Revised" License
4 stars 4 forks source link

How to truncate number with decimals? #29

Closed javierpe closed 6 years ago

javierpe commented 6 years ago

21.599999999999998 to 21.59

rowanseymour commented 6 years ago

Take a look at the FIXED function https://github.com/rapidpro/expressions/blob/master/python/temba_expressions/functions/excel.py#L50

javierpe commented 6 years ago

These function gets 21.6

rowanseymour commented 6 years ago

It has a second parameter which is the number of decimal places, e.g. @(FIXED("21.59999", 2)). It will round to 2 decimal places so you'll get 21.60

If you want to only round down, try @(ROUNDDOWN("21.59999", 2))