Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How do I multiple a number after it rounds up?

Avatar

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
jeanette614
Level 3

30-12-2013

I have a form asking for miles traveled. I need what they enter to round up to the next nearest whole mile. I have called that field "mileage". I have set it to whole numbers and it rounds up nicely for display. Now I need to multiple that new rounded "mileage" number by .56 (that field is called "auto"). What I currently have in the "auto" field is: mileage*.56  Unfortunately, it still uses whatever they type in to calculate with and not the rounded up "mileage" whole number.

What script do I need on which field to make the 56 cent calculation apply to the rounded up mileage and not the entered amount which it's currently doing?

Accepted Solutions (0)

Answers (7)

Answers (7)

Avatar

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
jeanette614
Level 3

31-12-2013

Gosh I'd love to learn how to do that some day. That works perfectly. Now hopefully he won't request something else that I don't know how to make work but thanks again and I wish you a great New Year.

Avatar

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
jasotastic81
Level 4

31-12-2013

Since the javascript built-in functions aren't working quite right, I'd recommend an if-statement to do the job. This works in the "exit" event for your mileage.

var toRound = this.rawValue;

 

if (toRound%1 >= .5) toRound = Math.ceil(toRound);

else toRound = Math.floor(toRound);

 

tfPayout.rawValue = toRound *.52;

this.rawValue = toRound;

As always, change the name tfPayout to whatever you need it to be so that it puts the product where you want.

Avatar

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
jeanette614
Level 3

31-12-2013

Well, I spoke too soon so I'm starting this thread again. The above script works great except it rounds everything to the next highest number. The requestor would like everything from 2.0 to 2.4 to round DOWN and everything from 2.5 (or whatever number they are entering) to round UP.

I tried changing the command in this script from "ceil" to "round" which does work just fine except now the amount for the "Payout" calculates the entire amount they typed in the mileage field. If they typed 2.4 miles, the miles round down and display as 2 but the Payout still calculates 2.4  x .56. How do I make it now use the "rounded" number to multiply by? I spent all morning trying different combinations of things hoping it was just a simple fix but nooooo. Please help!

Avatar

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
jeanette614
Level 3

30-12-2013

Thank you for your patience and yes, you're a genius, it works perfectly. Now I can finish out my project and know that it works well. Have a great New Year's.

Avatar

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
jasotastic81
Level 4

30-12-2013

I put them both in the exit event for the mileage text field that the user would fill out. Make sure that the calculated line (which I called tfPayout) is readOnly. Copy/paste the above script (both lines) into the exit event, and then change tfPayout to whatever you named the field that the product goes in.

The first line changes the value to a whole number by rounding. The second line then calcualtes the product of the integer and .56 and puts that number in the field for your payout.

Avatar

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 3
jeanette614
Level 3

Likes

5 likes

Total Posts

129 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
jeanette614
Level 3

30-12-2013

Ok, now I'm really confused.

Do both of these script lines go into the field where they enter the miles called "mileage" or the field where it calculates *.56 called "auto" or one in each?

Avatar

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
jasotastic81
Level 4

30-12-2013

I don't know what you used for field names, but I'm using tfPayout for the field that records the mileage time .56. (I'm presuming this is for a mileage reimbursement.) This code works.

this.rawValue = Math.ceil(parseInt(this.rawValue) + 1);

tfPayout.rawValue = Math.ceil(parseInt(this.rawValue)) * .56;

For some reason Math.ceil(x) is rounding down on my PC, so I added the "+ 1". That may be an issue with an update, or it may just be an issue for me. I would recommend checking with a few floats to be sure what your version is doing. Also, that Math.ceil(x) covers the rounding so you don't have to modify the result by setting to whole numbers.