`d.toString().trim('0')` would be one way
# announcements
r
d.toString().trim('0')
would be one way
m
That would remove leading zeros too, wouldn't it?
p
exactly, but
trimEnd()
will do the job
πŸ‘ 1
r
@mg6maciej It would, but I think
Double.toString()
doesn't contain any leading zeroes by default. Of course if you're also formatting and want leading zeros that's another thing.
m
It does πŸ™‚
0.123
πŸ‘ 1
trimEnd('0')
is not enough if you have
"1.000"
.
r
Ooooohhh... Not my brightest moment right there πŸ˜†
p
and
β€œ1.0”.trimEnd(β€˜0’)
returns
1.
πŸ™‚
l
I was also thinking, why would you want to turn
1000
into
"1"
? This
trimEnd
technique would do that.. would that be expected?
p
No, what I want to achieve is:
if (d == Math.floor(d)) "%.0f".format(d) else d.toString()
l
right! so
trimEnd
should work