Solved

Posted on 2007-10-17

Hi,

I am using the Math.Round function to round my values to two decimal places but when I use the value 0.125 it gets rounded to 0.12 and not 0.13 which is what I require.

This adheres to the docs quite happily but not what I want!

"The number nearest d with precision equal to decimals. If d is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of d is less than decimals, then d is returned unchanged."

I have also tried Decimal.Round to no avail.

Any thoughts?

Many thanks.

James.

I am using the Math.Round function to round my values to two decimal places but when I use the value 0.125 it gets rounded to 0.12 and not 0.13 which is what I require.

This adheres to the docs quite happily but not what I want!

"The number nearest d with precision equal to decimals. If d is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of d is less than decimals, then d is returned unchanged."

I have also tried Decimal.Round to no avail.

Any thoughts?

Many thanks.

James.

15 Comments

I need 0.124 still to be 0.12.

change it into a string.

loop into it and start from back.

Inside loop you can convert the currently pointed character to int

here yop can put your own custom conditions into th loop.

Hope this helps.

Not for me (this is in VS2003. I havent tried it in VS2005 yet).

decimal d = 0.125M;

MessageBox.Show(Decimal.Ro

Gives 0.12

What an interesting solution. I wonder why that works!!??

aschots,

Just about to test yours.

By clicking you are agreeing to Experts Exchange's Terms of Use.

Title | # Comments | Views | Activity |
---|---|---|---|

How to get boolean result of md5sum from two files in powershell | 8 | 46 | |

How can i Install a new Data Source on Visual Studio | 2 | 51 | |

Sort Datagrdview programmatically | 19 | 25 | |

What is MicroStrategy.NET? | 2 | 21 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**10** Experts available now in Live!