Round / Format a decimal value

Get help using Construct 2

Post » Sun Sep 18, 2011 11:30 pm

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...
B
4
S
1
G
2
Posts: 14
Reputation: 1,328

Post » Sun Sep 18, 2011 11:38 pm

Try: round(N * 100) / 100
for 2 decimal places, or 1000 for 3 decimal places, etc...
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,610

Post » Mon Sep 19, 2011 4:42 pm

[QUOTE=Ashley] Try: round(N * 100) / 100
for 2 decimal places, or 1000 for 3 decimal places, etc...[/QUOTE]

Ah thanks! Did not think of that myself.
B
4
S
1
G
2
Posts: 14
Reputation: 1,328

Post » Mon May 27, 2013 10:49 pm

I couldn't figure this out until I found this post! aquinn2013-05-27 22:50:09
B
23
S
7
G
1
Posts: 186
Reputation: 2,691

Post » Mon Sep 16, 2013 10:32 pm

Great find had no idea how was going to do it since Format(# of decimal places) isn't something I was able to find
B
39
S
12
G
6
Posts: 136
Reputation: 6,322

Post » Tue Jun 09, 2015 6:01 am

Message: yanmercal is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
Check this one.....Mercal
B
2
Posts: 1
Reputation: 152

Post » Tue Nov 03, 2015 7:52 am

For me this returned the same value as it began with
B
21
S
8
G
1
Posts: 83
Reputation: 2,194

Post » Tue Nov 03, 2015 7:58 am

Kenthria wrote: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?
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,850
Reputation: 48,301

Post » Tue Nov 03, 2015 9:48 am

For me i'm doing round(AResourceValue * 1000000) / 1000000- and if the ARV is 1,345,657 the end value is the same.
B
21
S
8
G
1
Posts: 83
Reputation: 2,194

Post » Tue Nov 03, 2015 9:55 am

For me i'm doing round(AResourceValue * 1000000) / 1000000- and if the ARV is 1,345,657 the end value is the same.
B
21
S
8
G
1
Posts: 83
Reputation: 2,194

Next

Return to How do I....?

Who is online

Users browsing this forum: farfetchd83, Laurent, makkancs, Yahoo [Bot] and 28 guests