How do I display X digits after . even if 0 (rvrs Zeropad?)

Get help using Construct 2

Post » Sun Feb 15, 2015 5:19 pm

Hi,

I'm looking for the simplest way to display a constant number of digits on the display, also decimals.

"Zeropad" does the trick before the dot, but I need to fill up the decimals from behind. (The clock-solution does not work here, since there you always fill up zeroes from the left.)

Examples:

00.00 (= Returned Value: 0)
01.00 (= Returned Value: 1)
01.10 (= Returned Value: 1.1)
01.11 (= Returned Value: 1.11)


BEST would be a solution, where no calculation is needed (like Zeropad) to save CPU.


Grateful for some advice ;)
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Sun Feb 15, 2015 6:15 pm

Here's an example using the time expression:
zeropad( int(time),2) & "." & zeropad(int(time*100)%100,2)
ImageImageImage
B
71
S
19
G
159
Posts: 3,400
Reputation: 92,451

Post » Sun Feb 15, 2015 10:54 pm

> @blackhornet

Thanks, but that does not help, as I described:

"The clock-solution does not work here, since there you always fill up zeroes from the left."
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Sun Feb 15, 2015 10:57 pm

Still, I just came to an idea: It might work if I do it for each digit! If no other solution comes up, I will try that. But maybe there is a simpler way?
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Sun Feb 15, 2015 11:01 pm

int(time) & "." & int(time*100)%100
ImageImageImage
B
71
S
19
G
159
Posts: 3,400
Reputation: 92,451

Post » Sun Feb 15, 2015 11:19 pm

No there you have to count too much.. I now think of len(), i tried that, but that also needs a loop to fill up each missing character at the end with a 0.

Still looking for a more effective solution!
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Sun Feb 15, 2015 11:30 pm

> @blackhornet : ok man, I got it... thanx
B
8
S
3
Posts: 197
Reputation: 1,207


Return to How do I....?

Who is online

Users browsing this forum: oddreal and 1 guest