• 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: decimal separating point
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: decimal separating point
      • From: Doug McNutt <email@hidden>
  • Prev by Date: as is what?
  • Next by Date: Default dir for choose file name
  • Previous by thread: Re: decimal separating point
  • Next by thread: Re: decimal separating point
  • Index(es):
    • Date
    • Thread