Number picture to clip trailing zeros in a decimal number

Don’t ask why, I just need to figure out a way for a number picture which would clip off zeros.
So 198,80 should become 198,8
If 198,65 it’s left as it is. and 198,00 become 198 of course
Note that my decimal separator is comma, not dot.

So user can enter any integer or decimal number (with max 2 decimal places) but I need to reformat it as above. Entry picture is N-10.`2

Any idea without bunch of IF sentences?

Thanks

Bostjan

Pretty simple loop backwards in a function. Don’t think there’s a picture for this.

How about assigning the decimal variable to a string and display the resulting string. I think that is how I have clipped the trailing decimal zeros in the past. If you are dealing with the issue on-screen for a data entry field then perhaps use a STRING variable for input with a KEY-IN template instead of a PICTURE.

The commas tripped me up, despite Bostjan’s warning.
As long as you’re talking only about the right side of the “decimal”, I’ve done exactly what you’ve suggested, in the past.

I ended up without formatting the output value. So user still has @n-10.`2 but I deal with the number unformatted. Only thing I do is use Stringtheory to replace dot with comma. The rest works by itself actually.

1 Like

sounds like you have it sorted Bostjan.

But for future reference, seeing you mentioned StringTheory I probably should add that the st.trim method allows you to specify an “alphabet” - a list of characters to remove from the start and end of a string.

st.trim(‘0<32>’) ! remove spaces and zeroes from beginning and end of string

https://www.capesoft.com/docs/StringTheory3/StringTheory.htm#Trim

if you use it without a parameter it just gets rid of spaces

cheers

Geoff R

1 Like