# 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

4 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

Try this:

Str.ToString.TrimEnd(β0β.TocharArray).TrimEnd(β.β.TocharArray)

if its 170 it will leave 17

1 Like

This one worked. thanks buddy

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