Re: number with one decimal
Re: number with one decimal
- Subject: Re: number with one decimal
- From: Deivy Petrescu <email@hidden>
- Date: Tue, 19 Jul 2011 15:38:39 -0400
On Jul 18, 2011, at 15:26 , Willem wrote:
> I am stuck with rounding an number to one decimal, something strange is happening. I have this applescript in Xcode 3.1.4:
>
> line 1: set aantalvragen to contents of text field "aantalvragenveld" as integer -- aantalvragenveld is a field where i can put in the number of questions on a test (voor my students)
> line 2: set aantalgoed to contents of text field "aantalgoedveld" as integer --aantalgoedveld is a field where i can put the number of correct questions
> line 3: set resultaat to (aantalgoed * 90 / aantalvragen) + 10 as integer --now the result is between 10 and 100, but it schould be between 1 and 10 (in Holland we like this ;)
> line 4: set contents of text field "Resultaatveld" to resultaat / 10 --and now its between 1 and 10 with one decimal.
>
> But, the strange thing is when aantalvragen is 10 and aantalgoed is 8 , then in line 3 resultaat is 82 (thats oke), but in line 4 its 8,19999999999999 (this should be 8,2)
>
> So applescript thinks that 82 / 10 = 8,1999999999
>
> It does not work to round things.
>
> As i said, i am stuck
>
> hope you can help
Firstly, Mathematically speaking
8.19…= 8.2 (infinite number of 9s)
Secondly, why do you need 4 lines if you can make it in 3 ?
line 3: set resultaat to (aantalgoed * 9 / aantalvragen) + 1 as integer --now the result is between 1 and 10
By the way, I do understand what you are doing, but shouldn't you put some check to make sure that aantalgoed is less or equal to aantalvragen ?
Deivy Petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden