# Keep last decimal digit 0 of a variable

Get help using Construct 2

### » Wed Sep 18, 2013 9:12 pm

I was checking the below tutorial Decimals in a float and here is my workaround:

Create the global variables:
tNumber (text variable)
fNumber (float variable)

Later set tNumber = left( str(fNumber), find( str(fNumber), ".")+3)

fNumber = 5003.563373
tNumber = 5003.56

fNumber = 78.30048573
tNumber = 78.30   <-- last digit stays 0

So what does the argument do?
left(text, number) takes the text and returns number of characters

The number of characters is set by find-function, which looks for the "." and adds the "." plus two additional characters (therefore 3 has to be added)

fNumber = 5003.563373
The dot "." is on position 4, but left()-function will return 5003

Therefore we need to add 3 and this gives 5003.56 (7 characters in total).

If variable *numberOfDecimals* (int) is required, simply define this variable.

The formula is now:
set tNumber = left( str(fNumber), find( str(fNumber), ".")+numberOfDecimals+1)Dan722013-09-18 21:46:21
B
37
S
16
G
3
Posts: 16
Reputation: 6,051

### » Tue Jun 30, 2015 9:24 pm

Great solution!!
I was looking for this like crazy
B
8
S
1
Posts: 3
Reputation: 472