Re: decimal separating point
Re: decimal separating point
- Subject: Re: decimal separating point
- From: Götz Verdieck <email@hidden>
- Date: Sat, 23 Aug 2003 14:07:48 +0200
>
At 6:39 PM -0400 22/08/03, Marc K. Myers wrote:
>
>> From: Goetz Verdieck <email@hidden>
>
>> To: AppleScript Users <email@hidden>
>
>>
>
>> Hi,
>
>>
>
>> I want to create parameters for a do script like :
>
>> set ar_list to " "& co05_w
>
>> do shell script "perl " & p_path & p_name & ar_list
>
>>
>
>> The problem is the original value for co05_w is : 103.1822047245
>
>> As soon as I put the value in the string it turns to 103,1822047245
>
>>
>
>> The decimal separating point turns to a: ,
>
>
>
> It has everything to do with the German language settings, where the decimal
>
> separator is designated to be a comma.
>
>
>
> You can either change the setting for the decimal separator in the "Numbers"
>
> tab of the International preferences panel or you could use AppleScript's
>
> text item delimiters to change the commas to decimal points after you convert
>
> the value from a number to a string.
>
>
Regarding the latter proposition, be aware that as long as you stay with the
>
comma as the decimal separator your AppleScript will be unable to perform some
>
kinds of operations that other can. For instance, converting a list of numbers
>
into a string and back will be more difficult:
>
>
--------------------- untested
>
count (run script "{get pi}")
>
---------------------
>
>
Emmanuel
So finally I found a solution.
(The trim_line() routine is from the apple scripting site.
The problem was the local decimal setting.
Thanks to everybody for the feedback.
This is my code, not very elegant, but it works:
-- I have this : 111,645477464545
-- I want this : "111.645477464545"
Set mysolution to split_real(111,645477464545) as string
on split_real(col_w) -- Aufspalten eines real und speichern als string
set frak_teil to col_w mod 1 as string -- = 0,182205 dann 0,1 abtrennen
set frak_teil to my trim_line(frak_teil, "0,", 0)
set ganz_teil to col_w div 1 as integer
set zusammen to ganz_teil & "." & frak_teil as string
return zusammen
end split_real
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as
string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as
string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.