trim() should be able to cut off trailing or leading zeros
LadyCailinBot opened this issue ยท 9 comments
CMDHELPER-3098 - Reported by macjuul
Since trim() cuts of trailing & leading white spaces, it would be handy if it would also cut off trailing/leading zeros in both integers and doubles
Comment by macjuul
Oh no I mean like in printing it so instead of messaging someone 1.0 it would instead message 1
It would also change for example 42.1300 to 42.13
Comment by PseudoKnight
I use round() for that. Though, I guess you're saying sometimes it'll be 1.0 and sometimes it'll be 1.1, and you want it to display as integer in the one case. 42.1300, however, would always display as 42.13 unless it was explicitly a string.
Comment by macjuul
Well thanks! But still, I don't exactly understand it. I'll make some examples:
1 will stay 1
1.5 will stay 1.5
1.0 will change to 1
Essentially the unnecessary zeros would be cut off
EDIT:
I currently use this to get the desired effect:
proc _trim_zeros(@n) {
@s = split('.', @n)
if(array_size(@s) == 1) {
return(@n)
}
if(@s[1] == 0) {
return(floor(@n))
}
return(@n)
}
Comment by PseudoKnight
Also, I already mentioned that in the second sentence of my last response.
Comment by PseudoKnight
A better way, in this case, would be to just test if the double is_integral().
Comment by macjuul
The number is coming from a command variable. First the variable gets devided by 10 and later on it (sometimes) gets multiplied by 10 again, so it might come out as something like 8.0, but I want it to show up as 8