You want to do two things in single shot:
-
Get the integer value if first digit after decimal is 0
-
Get the rounded value upto last 2 digits if its first digit after decimal is not 0.
For second option you can use:
newValue = Math.Round(value, 2)
Now comes the first requirement:
Once you get the decimal with 2 digits after decimal, get last two digits:
int decimalValue= (int)((newValue - (int)newValue ) * 100);
if(decimalValue < 10)
{
newValue = Math.Floor(value);
}
1
solved Math.Round doesn’t behave like i want it to. (X.0xxxxx numbers) [closed]