```
double noo = Convert.ToDouble(txttotalamount.Text);
noo = Math.Round(noo, 1);
string numString = string.Format("{0:###0.00}", Math.Round(noo, 2, MidpointRounding.AwayFromZero));
```

14,304,866 members

See more:

Hello friends,

Good Evening

I want to covert the decimal values to the nearest decimal number i.e

Suppose my value is

87.6408

then O/P should be either 60 if below 5 and 70 above 5

87.60 or 87.70

Any help will be appreciated. I have tried

noo = Math.Round(noo, 2,MidpointRounding.ToEven);and also

noo = Math.Round(noo, 2,MidpointRounding.AwayFromZero);This is working but not as I want. Please help.Thank You

Good Evening

I want to covert the decimal values to the nearest decimal number i.e

Suppose my value is

87.6408

then O/P should be either 60 if below 5 and 70 above 5

87.60 or 87.70

Any help will be appreciated. I have tried

noo = Math.Round(noo, 2,MidpointRounding.ToEven);and also

noo = Math.Round(noo, 2,MidpointRounding.AwayFromZero);This is working but not as I want. Please help.Thank You

```
double noo = Convert.ToDouble(txttotalamount.Text);
noo = Math.Round(noo, 1);
string numString = string.Format("{0:###0.00}", Math.Round(noo, 2, MidpointRounding.AwayFromZero));
```

Comments

This is same as Solution 5. You have to post it under solution 5 as your comment. You cannot take another solution and post as your solution.

Convert the decimal ToString("#.##")

this leads to "12345.67"

Read the last char from string and decide if it should be down or up (60 or 70)

this leads to "12345.67"

Read the last char from string and decide if it should be down or up (60 or 70)

Comments

Will you please elaborate sir.Please

The way you describe your problem already holds the answer. You want to do rounding to 87.60 or 87.70 for example. You do rounding to two decimal values but actually you want one decimal, meaning you would like to round to 87.6 or 87.7 (the extra zero would only be for display and has no meaning for the number itself)

Good luck!

Good luck!

Comments

Ya that's right but I am converting this value in word format so while printing i need to Print .60 or .70 to sixty or seventy paise.Please help me

Just use this to format it for display: String.Format("{0:0.00}", 87.6); -> 87.60

You may try

0.00 in the format string ensures that .6 is printed as 0.60.

If your problem is solved, you can accept and vote the solution, so that other users can know that the question is answered, and they can view it if required. Otherwise please post your queries.

PES

`string numString = string.Format("{0:####0.00}",Math.Round(num,2, MidpointRounding.AwayFromZero));`

0.00 in the format string ensures that .6 is printed as 0.60.

If your problem is solved, you can accept and vote the solution, so that other users can know that the question is answered, and they can view it if required. Otherwise please post your queries.

PES

Comments

Thank you sir it is working as per my requirement for big decimal number but when the I/P is like 112.36

then it the O/P is Rupees One Hundred Twelve and Thirty Six Paise Only ,I want the paise should be forty instead of Thirty Six. Please help

then it the O/P is Rupees One Hundred Twelve and Thirty Six Paise Only ,I want the paise should be forty instead of Thirty Six. Please help

Then put Math.Round(num,1,MidpointRounding.AwayFromZero), the 112.36 will be rounded to 112.4 and printed as 112.40

Thank you sir.

If your requirement is fulfilled then you may accept and vote the solution, so that other users can see that the question is already answered. Otherwise please post your queries.

PES

PES

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100