I have String
amount in a TextBox
, which I want to divide by 100.
The value should round off to two decimal places. I tried and I am not getting a proper value.
Here is what I tried:
6766/100 = 67.66
47/100 = .47
98/100 = .98
I have String
amount in a TextBox
, which I want to divide by 100.
The value should round off to two decimal places. I tried and I am not getting a proper value.
Here is what I tried:
6766/100 = 67.66
47/100 = .47
98/100 = .98
Use Math.Round. This example should get you going
string txtText = "78907";
double inputValue;
if (double.TryParse(txtText, out inputValue))
double result = Math.Round(inputValue / 100, 2);
Output: 789.07
Use Math.Round
, but one of both need to be a decimal type to avoid integer division:
double result = Math.Round(6766d / 100, 2);
Use Math.Round
. It has a parameter called precision.
Example:
Math.Round(1.23456, 2) -> 1.23
Math.round will do.
Math.Round(1.23456, 2);
It will round input at 2 decimals