• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: number with one decimal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: number with one decimal


  • Subject: Re: number with one decimal
  • From: Steve Thompson <email@hidden>
  • Date: Tue, 19 Jul 2011 00:28:06 +0100


On 18 Jul 2011, at 23:16, Mark J. Reed wrote:

Any computer software using floating-point arithmetic shares
AppleScript's opinion on that.  

Not true. Some software handles it better than others.

This is a rounding problem, but if all
you care about is the output, just fake the division when you do the
string conversion yourself.  Assuming scale is an integer:


Scale is always an integer. You can't have 3 and a half decimal places


(text 1 through -2 of (scale as text)) & "." & (text end of (scale as text))

That moves the decimal point if you're dividing by 10. It doesn't work for any other divisor or any values between -9 and 9.  However, rounding errors in AS exists for all divisors and dividends.

I think you misread my code - open up Terminal and type 

echo "scale=12;1/98" | bc

You'll get the answer

.010204081632

bc has no problems with rounding so if I encounter this problem I pass all my calculations off to bc instead of letting AS deal with it.

Steve


___________________________________________________
Steve Thompson

http://about.me/stetho



 _______________________________________________
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

  • Follow-Ups:
    • Re: number with one decimal
      • From: "Mark J. Reed" <email@hidden>
References: 
 >number with one decimal (From: Willem <email@hidden>)
 >Re: number with one decimal (From: Steve Thompson <email@hidden>)
 >Re: number with one decimal (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: number with one decimal
  • Next by Date: Re: number with one decimal
  • Previous by thread: Re: number with one decimal
  • Next by thread: Re: number with one decimal
  • Index(es):
    • Date
    • Thread