Mudsaf Posted August 25, 2013 Share Posted August 25, 2013 Hello, i'm wondering which method i need to use tho get these values below working. 1 //This should return 11.2 //This should return 21.00001 //This should return 12.5 //This should return 33 //This should return 3 and so on, i guess you'll get my point. I've see that Math.round(); fixes it like decimal should work, but i want the number to go rounded to next higher number. Link to comment Share on other sites More sharing options...
Ingolme Posted August 25, 2013 Share Posted August 25, 2013 Math.ceil() will round up to the next number, but 1.00001 will round up to 2 as well. It's up to you to decide a threshold and create a function that chooses Math.ceil() or Math.floor() depending on what value it has. Link to comment Share on other sites More sharing options...
davej Posted August 25, 2013 Share Posted August 25, 2013 (edited) LOL function rnd(u){if(u==1) {return 1}else if(u==1.2) {return 2}else if(u==1.00001) {return 1}else if(u==2.5) {return 3}else if(u==3) {return 3}else {return "this is a code joke!"}} Edited August 25, 2013 by davej Link to comment Share on other sites More sharing options...
Mudsaf Posted August 27, 2013 Author Share Posted August 27, 2013 Math.ceil() will round up to the next number, but 1.00001 will round up to 2 as well. It's up to you to decide a threshold and create a function that chooses Math.ceil() or Math.floor() depending on what value it has. Thanks LOL function rnd(u){if(u==1) {return 1}else if(u==1.2) {return 2}else if(u==1.00001) {return 1}else if(u==2.5) {return 3}else if(u==3) {return 3}else {return "this is a code joke!"}} Lol x) Link to comment Share on other sites More sharing options...
davej Posted August 28, 2013 Share Posted August 28, 2013 Now seriously -- such a function can do whatever you might want -- as long as what you want makes sense. You would probably need to also make use of ceil(), floor(), or round(), or some combination of them. http://www.w3schools.com/jsref/jsref_obj_math.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now