Limit the 3 digits after the decimal point


Hi, I need to limit the number after the decimal point as reported on the capture, and here is the other source code capture, and round it like 0.026cbm

Help me please.

You can use the roundTo() expression

roundTo(number, number of places)

https://wiki.gdevelop.io/gdevelop5/all-features/expressions-reference/#mathematical-tools

1 Like

The roundto expression allows you to set a max decimal. I’d recommend using that via the expresion builder in the engine.

Edit: Keith beat me to it above.

1 Like

can you make screenshot for me please?

Put your variable inside the roundTo() expression followed by a comma and the number of places.

ToString(roundTo(Variable(Calculator), 3))

Note: if the variable is declared in the variable screen you no longer need Varauable(), you can use the variable name.

ToString(roundTo(Calculator, 3))

You can type it or click the expression builder button. That button with the E like character and “123” or “abc” depending on the expected format.

1 Like

thanks, I try it now


Woow, its work perfectily, thank you so much :heart_eyes:

1 Like