Jan 16, 2019

How to round decimals (Beginner Help)

6 comments296 views


How can I round a calculated value?

I currently have a calculation showing 1.0833333333333

Is there any way I can shorten this to just 1.08 or round u or down?

I have googled math.floor() and math.round() but I cant wrap my head around how this would fit into my code

would appreciate your help!


Jan 16, 2019

This is the formula i need rounded

$w("#age1").text = "" + (Number($w('#totalmonths1').value) /12) from 1.08333333333 to just 1.08

Jan 16, 2019
Best Answer

Hi, Shaneice.

Does replacing the following code:

 $w("#age1"#age1").text = "" + (Number($w('#totalmonths1'#totalmonths1').value) /12) 

with the following code:

 $w("#age1"#age1").text = (Number($w('#totalmonths1'#totalmonths1').value) / 12).toFixed(2).toString();

do what you want?

Jan 16, 2019

You might have to remove the extraneous "#age1" (two/2 occurrences) and '#totalmonths1' (two/2 occurrences) that somehow got included/inserted into my response (which I could not then subsequently edit to remove).

Jan 16, 2019

Yes! It worked!!!!

I've been trying to figure this out for WEEKS!! and you helped in minutes!

I appreciate it @abergquist

Jan 16, 2019

quick question if you think you can help?

for future purposes I may need to round up to the nearest tenth

EX: 1.08 rounded up to 1.1

is this possible? Thanks!

Jan 16, 2019

You're welcome!

Log In to Comment
Get in on the conversation.
Sign Up Today
Not a member yet? Join our community to post and comment.