• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rounding?  RSS feed

 
Jesus Doe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish to learn how to round double varaibles without using math.round(); I have a rough idea of what might work but have been unable to execute it or get it set up right.I was thinking of maybe have the input divide by 1 but only retaning the remainder, and then comparing the remainder with .49 and .50 and depending on which one is true lets say the remainder is less than or equal to .49 then i would only ask to print the int of lets say num1 and then if the remainder is greater than or equal to .50 then to num1 add 1. I dunno Help?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would then test the method with 3.49123.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> without using math.round();

one of the ways is to add .5 to the number, cast to int, then recast to double
12.345 --> 12.0
34.567 --> 35.0
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!