Page 1 of 1
Rounding up or down numbers
Posted: Sat May 17, 2014 1:54 pm
by dazza the stag
Ok - here goes my first post, this is my first small app that I am developing and so far have been able to tackle the basics through questions already asked in forum, this one seems really simple but Im not sure where exactly i need to put the command as everything i have tried throws up an error message
This is what i currently have
on mouseUp
put field MonthlyRentalIncomeReceived /6.75 /125 * 10000 * 12 into field MortgageAmountResult
end mouseUp
so user inputs a number and then the above calculation is done and the result placed into another field. I simple want to round the result either up or down ( it will be up in one field of the app and down in another field so they will be separate, to the nearest integer
Thanks in anticipation
Dazza
Re: Rounding up or down numbers
Posted: Sat May 17, 2014 2:38 pm
by atout66
Hi dazza,
You have the trunc() function in the dictionnary and the round() one too.
The round() one should be OK for your needs
Kind regards, Jean-Paul.
Re: Rounding up or down numbers
Posted: Sat May 17, 2014 2:48 pm
by FourthWorld
There's also the statRound function, worth knowing both to pick the one best suited for the needs of the project at hand.
Re: Rounding up or down numbers
Posted: Sat May 17, 2014 6:38 pm
by dazza the stag
Sorry - probably didn't explain that one too well...I have looked at the dictionary and those commands but I just can't work out where to put it, so in the script above where would i place it, in with line that has got the calculation in it, or on its own separate line ?
Would really appreciate an example, lets say if i wanted to round up the result ?
Thanks
Dazza
Re: Rounding up or down numbers
Posted: Sat May 17, 2014 7:16 pm
by atout66
Hi dazza,
Try this in the commandWindow
Code: Select all
put 2.56 into val1
put 10 into val2
put round(val1 + val2)
It returns <13>; If you try with
it returns 12.6.
Does it help you like that ?
Sorry, I'm not a "pro"
Kind regards, Jean-Paul.
Re: Rounding up or down numbers
Posted: Sun May 18, 2014 11:04 am
by dazza the stag
Hi jean Paul
I always appreciate help - thank you but can we go back a step, if I have
on mouseUp
put field MonthlyRentalIncomeReceived /6.75 /125 * 10000 * 12 into field MortgageAmountResult
end mouseUp
showing when i click "script" for this particular button - I assume that is the command window ? Could you tell me what I need to add to the above to round down the result. SO as an example lets say the field MonthlyRentalIncomeReceived has a value of 100000, therefore after doing the calculation the result is 703.125, what do I add to that script and where to give the answer 703 ?
When I interpret what you have put ( which clearly I have got incorrect) I have changed it to the below which doesn't work because i get an error message
on mouseUp
put round ( field AmountofMortgage *6.75 *125 / 10000 / 12 into field RentalIncomeRequiredResult,1)
end mouseUp
Maybe I am not understanding this and I need to put this round command somewhere else ? Thank you for bearing with me its just my inexperience
Thanks
Dazza
Re: Rounding up or down numbers
Posted: Sun May 18, 2014 11:35 am
by FredBeck
Hi Dazza,
The Round function applies to your formula, not to the result field!
Code: Select all
put round(fld myVar / 6.75 / 125 * 10000 * 12) into fld Result
Re: Rounding up or down numbers
Posted: Sun May 18, 2014 11:37 am
by dave.kilroy
Hi Dazza and welcome to the forum
Jean-Paul led you to up to 'standing-in-front-of-the-solution' - I'm now going to point you to the solution - try this:
Code: Select all
on mouseUp
put field MonthlyRentalIncomeReceived /6.75 /125 * 10000 * 12 into tVar
put round(tVar,0) into field MortgageAmountResult
end mouseUp
As you can see you need to apply Jean-Paul's code to the number you calculate - you could do it all in one line but I've used an extra variable (tVar) and an extra line for clarity
...BTW if you just want your code to 'work for now' then it's fine, but there are several ways you could improve it's format - and learning how to do so it will pay you back in the long-term
Kind regards
Dave
Re: Rounding up or down numbers
Posted: Sun May 18, 2014 11:40 am
by dave.kilroy
Hi FredBeck - wow you have to be fast on this forum - you got in ahead of me

Re: Rounding up or down numbers
Posted: Sun May 18, 2014 12:17 pm
by dazza the stag
Thank you to you both - Im not sure how I missed that, I must have tried every combination apart from the correct one !
I used Trunc in the end as it always plays on the safe side for what I need given that it always rounds down even though its not quite as accurate all the time in regard to the actual result because of this.
Thanks again
Dazza