# Round / Format a decimal value

0 favourites
• 26 posts
• Hello,

New Construct user here with a specific question:

Is there any quick way to round a float value to a specific number of decimals?

I notice in Construct Classic there is a "FormatDecimal(float, N)" function that seems to do exactly what I want but it does not seem to exist in C2.

Extracting the decimal part from a value and using a couple of string operations to get N decimals just seem very awkward...

• Try: round(N * 100) / 100

for 2 decimal places, or 1000 for 3 decimal places, etc...

• Try: round(N * 100) / 100

for 2 decimal places, or 1000 for 3 decimal places, etc...

Ah thanks! Did not think of that myself.

• I couldn't figure this out until I found this post! <img src="smileys/smiley20.gif" border="0" align="middle" />

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Great find had no idea how was going to do it since Format(# of decimal places) isn't something I was able to find

• Check this one.....Mercal

• For me this returned the same value as it began with

• For me this returned the same value as it began with

It works for me, for instance:

Set MyText.text to round(10.2345*100)/100 - returns 10.23.

What value(s) where you testing?

• For me i'm doing round(AResourceValue * 1000000) / 1000000- and if the ARV is 1,345,657 the end value is the same.

• For me i'm doing round(AResourceValue * 1000000) / 1000000- and if the ARV is 1,345,657 the end value is the same.

• round(x) is only for x= float value, if you try to round an integer, round(int) returns int

• For me i'm doing round(AResourceValue * 1000000) / 1000000- and if the ARV is 1,345,657 the end value is the same.

Seeing your expression it seems you want to be able to have 6 numbers behind your decimal point..

if you have a value of 1.5123456 it will become 1.512346 using this expression, so it works..

• No just 3, so it would eventually be 1.512m rather than 1.5123456.

• No just 3, so it would eventually be 1.512m rather than 1.5123456.

Than this should work:

round(AResourceValue * 1000) / 1000

• It doesn't but I just heard that the value cant be a whole number.

So I think round((AResourceValue / 1000000) * 1000)) /1000

should work.

• 26 posts