# Decimals and zeros being shown

Get help using Construct 2

### » Wed Aug 29, 2012 9:41 pm

Hi there,

I'm using this formula to show results with two decimals:
round(N*100)/100

But...

How could I show numbers this way?----> '456.00' instead of just '456'

Best regards!
B
16
S
4
G
1
Posts: 105
Reputation: 1,829

### » Thu Aug 30, 2012 1:09 am

It has to be a string to keep it displayed to two decimal points.

This works.. There's probably a simpler way to do it though.

I was gradually figuring it out and suddenly it started to look confusing as hell.

It basically isolates the decimals, multiplies by 100 and zeropads it, before putting it back into a string with the original integer. But I'll explain it further if you want.keepee2012-08-30 02:54:59
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Thu Aug 30, 2012 6:02 am

LOL @keepee
That is one long ass equation to add decimals points.
I believe that is the best way to do it though.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

### » Thu Aug 30, 2012 8:56 am

A simpler (and yet, not really ) way would be what you had, with a small addition:

N = round(N)? (N&".00"):(round(N*100)/100)

Using a fancy query thingy... It's actually not simpler at all, it's just a different kind of complicated. Simpler to ME because I use stuff like this all the time.

If you've never seen this before, it's checking to see if there even ARE any decimals; if there aren't, just add a ".00" at the end. If there are, do what you originally do.

(Edit: removed a pair of parentheses from the expression, just tested it and it gave a syntax error. Other than that it works fine)SullyTheStrange2012-08-30 09:33:43
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

### » Thu Aug 30, 2012 4:51 pm

@Rory
I know right? it's a bit crazy
@SullyTheStrange
I completely forgot you could do queries within expressions so thanks for the reminder..!

However that way won't work for when the number has one decimal place. 456.1 would still display 456.1 instead of 456.10
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Fri Aug 31, 2012 12:21 am

Keepee,your solution works great!! Thanks a lot friends!

I had spent already some nights working out how to solve this issue without success.

Two thumbs up!

B
16
S
4
G
1
Posts: 105
Reputation: 1,829

### » Fri Aug 31, 2012 5:38 am

Ahhh yeah you're right keepee. I could make it even more needlessly complicated by checking for that too... or he could just use your method. Either way's fine by me.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

### » Fri Aug 31, 2012 6:06 pm

Hi, I'll try to send you a sample of the code.

Now, the next step I'm looking foward is to limit the possible text entries between 0 and 360.

Do you think it's a good idea to create another global variable and then compare it to this values?
Or perhaps try to find an expression that could solve the issue without adding more variables?

I'll keep to find the solution!

Any extra idea?

Cheers!
B
16
S
4
G
1
Posts: 105
Reputation: 1,829

### » Fri Aug 31, 2012 6:08 pm

In the next post you'll find a link to the projectHeptagono2012-08-31 18:12:13
B
16
S
4
G
1
Posts: 105
Reputation: 1,829

### » Fri Aug 31, 2012 6:10 pm

B
16
S
4
G
1
Posts: 105
Reputation: 1,829

Next