math.round

This is C#. I am trying to do the same thing in C++ (VS2005) but can't seem to get the right combiniation.

1
2
sraise = Math.Round(sraise / 100, 1) * 100;
            sraise = Math.Round(sraise, 0);


I'm trying to round it to the nearest 10's place.
Last edited on
Streams round numbers, so you can use manipulators to get the number rounded

1
2
3
4
double n = /*something*/;
stringstream ss;
ss << setprecision(10) << n; // output the rounded number on the stream
ss >> n; // put the rounded value back to the number 
Notice that doubles themselves aren't much precise

This articles show how to round numbers using mathematics: http://www.cplusplus.com/forum/articles/3638/

- C# uses .NET, I don't suggest you using it with C++ -
Topic archived. No new replies allowed.