Page 1 of 1
[SOLVED] Always rounding a number up
Posted: Fri Jul 20, 2018 5:00 pm
by karmacomposer
Here is what I am trying to accomplish:
I need to round UP the subtotal all the time. I cannot round down at all.
So:
Code: Select all
round(field "fldTotalDeduction",2)
Would not always work. If fldTotalDeduction = 2.5, fine but if fldTotalDeduction = 2.2, not fine
Now, once I always round up, I need to take the difference and add that to a field.
So, if fldTotalDeduction = 500.23 and it rounds up to 501, I need the new variable to have .77 in it.
Any help is appreciated.
Mike
Re: Always rounding a number up
Posted: Fri Jul 20, 2018 5:25 pm
by karmacomposer
Why does this throw an error:
Code: Select all
function roundUp var
return round(var + 0.5)
end roundUp
Do functions have to be created at the top of a script or anywhere? Do they have to be in the card or stack script?
Mike
Re: Always rounding a number up
Posted: Fri Jul 20, 2018 5:34 pm
by SparkOut
Code: Select all
put field "fldTotalDeduction" into tFldVal
put trunc(tFldVal + 0.99) into tVal
put tVal && ":" && tVal - tFldVal
is a similar way to adding 0.5 to the round() function. If you add 0.99 then assuming there is an integer value of (say) 500 then it won't round up to 501 but remain as 500, also assuming this is what you want.
Functions have to be in the message path accessible from the place where the call is made. You can have the function in the same script as the mouseUp script of a button, for instance, in which case it will only be available to the button script. If you want it to be called from other objects, then card or stack script are more appropriate. Look up the message path - there is a super explanation of the implications of the message path at
http://www.fourthworld.com/embassy/arti ... _path.html
Re: Always rounding a number up
Posted: Fri Jul 20, 2018 5:38 pm
by karmacomposer
I found the answer and wrote it myself.
I'm so stoked!!!
Mike
Re: Always rounding a number up
Posted: Fri Jul 20, 2018 5:40 pm
by SparkOut
Great! It's a nice feeling to get there by yourself. Keep it up!