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
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
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.