---
title: "How to limit a calculated field with “real” to 1 number after the decimal?"
url: "https://openforis.support/questions/1244/how-to-limit-a-calculated-field-with-real-to-1-number-after-the-decimal"
tags: ["collect"]
status: "answered"
score: 0
answer_count: 5
asked: "2017-05-04T20:01:39"
last_activity: "2017-05-08T19:15:55"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# How to limit a calculated field with “real” to 1 number after the decimal?

Asked by flandsberg on 2017-05-04

Hi,

I have way too many numbers after the decimal of a calculated field. How can I limit the calculated field to 1 or 2 numbers after the decimal? 

Thanks for sharing your knowledge!

Florence


## Answer (score 0, by Stefano (OF) on 2017-05-05)

Link: https://openforis.support/questions/1244/how-to-limit-a-calculated-field-with-real-to-1-number-after-the-decimal/1247

Hi Florence,  
What you can do is to format the number that comes from your expression by wrapping it into the *format-number* function. Examples:  
 - limit a number to 1 decimal digit: **format-number(MY_NUMERIC_EXPRESSION, "#.0")**  
 - limit a number to 2 decimal digit: **format-number(MY_NUMERIC_EXPRESSION, "#.00")**  
Note that the **format-number** expression will truncate your decimal part... if you want to do something a bit more complex, then try to combine it with some other numeric functions, like *round*, *ceiling*, *floor*. All of these functions are core functions of the XPath language, you can find lots of documentation on internet ([here][1] for example).  
Thanks,  
Open Foris Team


  [1]: https://www.w3schools.com/xml/xsl_functions.asp#numeric


## Answer (score 0, by flandsberg on 2017-05-05)

Link: https://openforis.support/questions/1244/how-to-limit-a-calculated-field-with-real-to-1-number-after-the-decimal/1250

Thanks for the guidance. I tried using 

round((cropland_tree_count div cropland_area), "#.00")

while there is no error message in the validation rule, when I preview, I get an error message "2017-05-05T13:33:29.548Z - error updating data: undefined". I replaced the " with ' but it gave me the same error message.

Almost there!! 

Florence


## Answer (score 0, by Stefano (OF) on 2017-05-06)

Link: https://openforis.support/questions/1244/how-to-limit-a-calculated-field-with-real-to-1-number-after-the-decimal/1255

Hi Florence,  
The expression you wrote is wrong because the function *round* accepts only one parameter. In theory looks even wrong to me because it will cut the decimal part of the number... What you can do is for example this:  
**format-number(round(cropland\_tree\_count * 100 div cropland_area) div 100, "#.00")**  
In this way the result should be the expected one... Let us know!  
Thanks,  
Open Foris Team


## Answer (score 0, by flandsberg on 2017-05-07)

Link: https://openforis.support/questions/1244/how-to-limit-a-calculated-field-with-real-to-1-number-after-the-decimal/1256

Hi!

Well, I copy-pasted the expression (I don't understand it so much I have to say) but I end up with "2017-05-07T15:29:39.338Z - error updating data: undefined" error...

Sorry it is still a pending issue...

Cheers,

Florence


## Answer (score 0, by Stefano (OF) on 2017-05-07)

Link: https://openforis.support/questions/1244/how-to-limit-a-calculated-field-with-real-to-1-number-after-the-decimal/1257

Hi Florence,  
Probably this expression gives an error when one of the operands is null... try to specify this in the **Apply when** condition:  
**cropland_tree_count > 0 and cropland_area > 0**  
Also please don't forget that the **format-number** function will work only if you use it in a calculated "Text" attribute... otherwise the formatting can result in a invalid number error if used for a "Numeric" attribute. If you just need to limit the decimal digits, maybe using only the round/ceiling/floor functions will be enought...!  I hope it's more clear now!  
Thanks,  
Open Foris Team

> That worked beautifully, thanks!! Cheers Florence (flandsberg)
