• 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: Yosemite decimal number conversion error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yosemite decimal number conversion error


  • Subject: Re: Yosemite decimal number conversion error
  • From: Takaaki Naganoya <email@hidden>
  • Date: Wed, 29 Oct 2014 13:22:11 +0900

> 2014/10/29 12:44、Shane Stanley <email@hidden> のメール:
> On 29 Oct 2014, at 1:40 pm, Takaaki Naganoya <email@hidden> wrote:
>>
>> I found an error with decimal number conversion from AppleScript's ‘real' into Cocoa's ‘float'.
>> Is it well-known?
>
> I'm not sure that it's strictly an error, but the problem seems to be that the return value has a different precision. Storing floating-point values in binary form nearly always involves some rounding.
>
> If you need exact matching values, you could try this:
>
> on numberFloatWith:aNum
> 	set theNum to current application's NSNumber's numberWithFloat:aNum
> 	return (theNum's descriptionWithLocale:(current application's NSLocale's systemLocale())) as real
> end numberFloatWith:
>
> But that's going to be messy with lists.
>
> I guess the question is: Where and how does it really matter?

Thank you, Shane!
It is unthinkable way for me…. Like a magic.

I really stack with sorting number list with ASOC.
It was an easy task. But it brought me a heavy headache.


<AppleScript>
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

set aList to {1, 1, 10, 0.1, 1.1, -1, -100} --Original List
set aRes to sort1DNumList_ascOrder_(aList, true)
--> {-100, -1, 0.10000000149, 1, 1.100000023842, 10}--Result (!!!!)


--Sort 1-Dimension List(Number List)
on sort1DNumList:theList ascOrder:aBool
	tell current application's NSSet to set theSet to setWithArray_(theList)
	tell current application's NSSortDescriptor to set theDescriptor to sortDescriptorWithKey_ascending_(missing value, true)
	set sortedList to theSet's sortedArrayUsingDescriptors:{theDescriptor}
	return (sortedList) as list
end sort1DNumList:ascOrder:
</AppleScript>


--
Takaaki Naganoya
email@hidden
http://piyocast.com/as/




 _______________________________________________
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:
    • Timing is everything [Was: Re: Yosemite decimal number conversion error]
      • From: Shane Stanley <email@hidden>
    • Re: Yosemite decimal number conversion error
      • From: Shane Stanley <email@hidden>
References: 
 >Yosemite decimal number conversion error (From: Takaaki Naganoya <email@hidden>)
 >Re: Yosemite decimal number conversion error (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Yosemite decimal number conversion error
  • Next by Date: Re: Yosemite decimal number conversion error
  • Previous by thread: Re: Yosemite decimal number conversion error
  • Next by thread: Re: Yosemite decimal number conversion error
  • Index(es):
    • Date
    • Thread