Re: decimal separating point
Re: decimal separating point
- Subject: Re: decimal separating point
- From: kai <email@hidden>
- Date: Sun, 24 Aug 2003 06:29:16 +0100
on Sat, 23 Aug 2003 14:07:48 +0200, Gvtz Verdieck wrote:
>
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
I may be missing something here, but I still can't see what's wrong with
using text item delimiters:
on numToStr(v)
set d to text item delimiters
set text item delimiters to (0.0 as string)'s item 2
set v to (v as string)'s text items
set text item delimiters to "."
set v to v as string
set text item delimiters to d
v
end numToStr
set num to 111.645477464545
{num as string, numToStr(num)}
--> {"111,645477464545", "111.645477464545"}
---
kai
_______________________________________________
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.