https://kotlinlang.org logo
#announcements
Title
# announcements
r

robin

03/16/2017, 12:54 PM
d.toString().trim('0')
would be one way
m

mg6maciej

03/16/2017, 12:55 PM
That would remove leading zeros too, wouldn't it?
p

pawegio

03/16/2017, 12:57 PM
exactly, but
trimEnd()
will do the job
👍 1
r

robin

03/16/2017, 12:57 PM
@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

mg6maciej

03/16/2017, 12:58 PM
It does 🙂
0.123
👍 1
trimEnd('0')
is not enough if you have
"1.000"
.
r

robin

03/16/2017, 1:03 PM
Ooooohhh... Not my brightest moment right there 😆
p

pawegio

03/16/2017, 1:07 PM
and
“1.0”.trimEnd(‘0’)
returns
1.
🙂
l

leaudro

03/16/2017, 1:16 PM
I was also thinking, why would you want to turn
1000
into
"1"
? This
trimEnd
technique would do that.. would that be expected?
p

pawegio

03/16/2017, 1:21 PM
No, what I want to achieve is:
if (d == Math.floor(d)) "%.0f".format(d) else d.toString()
l

leaudro

03/16/2017, 1:22 PM
right! so
trimEnd
should work