Full Version : String Format
xmlspawner >>Scripting Support >>String Format


<< Prev | Next >>

Haazen- 09-07-2006
I have a variable double Bonus;
After a simple subtraction 5 - .1 it's value is 4.9000000001.

I display Bonus as part of the item name.
Name = m_Name + Convert.ToString(Bonus);

How do I format the Convert.ToString so the display would be 4.9 rather than 4.9000000001?

Thanks for reading.

I just discovered another side to this issue. I can end up with a value of .4999999999999. converting to int and back to double ends up .4 and should be .5.

So I guess what I'm trying to do is rounding . 4.90000000001 is 4.9 and 4.49999999999 is 4.5.

Any sugestions?


I solved My issue using Math.Round(Bonus,1)

This does simple rounding and sets to 1 decimal place.