ehigginbotham Posted January 20, 2017 Share Posted January 20, 2017 I need to round off a number. example, my number is 41.25 I want to multiply it by 1.25, and then round it always up to the next 5 increment. so 41.25 x 1.25 = 51.56 I need that number to come out to be 55. I have figured out how to round it, it just doesn't always round up. here is the final rule var x = parseInt(Rule("g1")) var mult = (x*1.25) var z = Math.round(mult / 5) *5 var y = parseInt(z) return y; here is rule G1 var x = parseFloat(Field("AMT")) var z = Math.round(x) var y = parseInt(z) return y; any ideas to make it always round up to the nearest 5 increment in whole numbers? Quote Link to comment Share on other sites More sharing options...
step Posted January 20, 2017 Share Posted January 20, 2017 (edited) As noted in this thread: Math.ceil rounds up, Math.floor rounds down and Math.round rounds to the nearest integer. So, you want to use Math.ceil: var x = parseInt(Rule("g1")) var mult = (x*1.25) var z = Math.[color="Red"]ceil[/color](mult / 5) *5 var y = parseInt(z) return y; That said, there is a little bit of redundancy in your code. In rule G1, why parseFloat (keeping decimals), then round to the nearest integer (drop decimals), and then parseInt (convert an integer to an integer)? It might be cleaner/easier to read if you just did something like this: return Math.ceil(Field("AMT") * 1.25 / 5) * 5; Edited January 20, 2017 by step grammar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.