I am having a value like below :
decimal val = 1.100;
Now what I am trying to do is if I am having 0 after first decimal point value then I want to take only 1.1 and ignore rest and if I am having 1.11 then I want to take whole 1.11
This is how I am thinking to do it:
Convert decimal to string.
Split string by dot.
Check if length is 2 and if second position is greater than 0 then take whole like 11 for decimal value 1.11 else if decimal is like this 1.10 then take 1.1 else take 1.0 in case of decimal 1.000
Sample input and output:
1.000 // output 1.0
1.100 // output 1.1
1.110 // output 1.11
1.111 // output 1.111
1.102 // output 1.102
But this is dirty logic which I want to avoid. Isn't there is any inbuilt way or better way to do this?
Note: I don't want to do any kind of round up.