How can you get decimal places to be rounded up? Like for instance if you had 3.125 and you wanted it to be output as 3.13.
public double roundMe(int positionRoundingTo, double original)
// I could do this for you but I would feel guilty if it was your homework.
// Therefore I'll do it by example:
// you seem to be wanting to go to two decimal places
double multiplier = 10.0 ^ (positionRoundingTo)
ie 100.0 = 10 ^ 2;
(since you want two decimal points)
3.125 * multiplier = 312.5
(3.125 * 100.0 = 312.5)
The trick with rounding is to add (0.5) once you have the decimal in the right spot.
312.5 + 0.5 = 313.0
then you keep just the integer portion of 313.0, resulting in 313.
you then make 313 back into a double.
then you divide it by that multiplier number determined above.
313.0/100.0 = 3.13
and return it as your answer:
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL