Trailing zeroes

Hie huyz. how can i remove trailing 0s for example 1.20 should be 1.2 and 12.00 should be just 12

1 Like

Concert it to double and then back to string

Additionally the Trim function can be used, just pass in β€œ0” and then β€œ.”.

Ex:
str = 12.00
str.Trim(β€œ0"c).Trim(”."c) = 12

"0"c is shorthand for β€œ0”.ToCharArray

Trim removes any characters on the front or back of the string that match the given character. If you pass Trim with no characters it trims whitespace.

1 Like

@Tapiwa

Str = β€œ1.20”

Str.ToString.TrimEnd(β€œ0”.TocharArray)

Hey @Tapiwa

Use - String.Format("{0:G10}", Decimal.Parse("<your Value>"))

Example-

String.Format("{0:G10}", Decimal.Parse("1.20")) // Output - 1.2

String.Format("{0:G10}", Decimal.Parse("12.0000")) // Output - 12

Regards…!!
Aksh

3 Likes

@lakshman
As is this would not convert β€œ12.00” to β€œ12”. It would leave it as β€œ12.”.

1 Like

@DanielMitchell

Will check once.

1 Like

@DanielMitchell @Tapiwa

Try this:

Str.ToString.TrimEnd(β€œ0”.TocharArray).TrimEnd(β€œ.”.TocharArray)

if its 170 it will leave 17

This one worked. thanks buddy

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.