Understanding numberformat

Klaus major-k klaus at major-k.de
Fri Apr 6 08:21:47 EDT 2018


Hi Mark,

> Am 06.04.2018 um 14:18 schrieb Mark Waddingham via use-livecode <use-livecode at lists.runrev.com>:
> 
> On 2018-04-06 13:17, Klaus major-k via use-livecode wrote:
>> Hi friends,
>> maybe I have a little understanding problem with numberformat.
>> Looks like this is "temporary/fleeting"?
>> Meanwhile I worked around this with the FORMAT() function,
>> but would like to understand the problem.
>> I have this button script:
>> ###############################################################
>> ## Neccessary function, since in most non-enlsih speaking countries like germany
>> ## we use the COMMA as a decimal delimiter
>> ## Neccessary for calculations
>> ## tZahl = tNumber
>> ## ohne_komma = without comma
>> function ohne_komma tZahl
>>  replace "," with "." in tZahl
>>  return tZahl
>> end ohne_komma
>> ## mit_komma = with comma
>> ## Neccessary for displaying numbers
>> function mit_komma tZahl
>>   replace "." with "," in tZahl
>>   return tZahl
>> end mit_komma
>> on mouseUp pMouseButton
>>   put 10  into menge ## amount
>>   put "2,3" into preis ## price
>>   set the numberformat to 0.00
>>   put ohne_komma(menge) into menge
>>   put ohne_komma(preis) into preis
>>   put  menge * preis into ergebnis ## result
>> ##!!!
>>   answer ergebnis ## -> 23.00
>>   answer mit_komma(ergebnis) ## -> 23
>> ##!!!
>> end mouseUp
>> ###############################################################
>> The last 2 lines of the mouseup handler are puzzling me, what do I not get?
>> Thanks for any insight!
> 
> The numberFormat is a local property and is only used when a number gets converted to a string...
> 
> put menge * preis into ergebnis -- ergebnis is a number
> answer ergebnis -- ergebnis is converted to a string using the numberFormat 0.00 and passed to 'answer'.
> 
> In the last line 'answer mit_komma(ergebnis)' you are passing ergebnis (a number) to a function. In the function, that number is converted to a string using the default numberFormat (as it is local to handlers, and you have not set it) as you are using 'replace' on it.
> 
> So, the 'issue' here is the locality of numberFormat.
> 
> Warmest Regards,
> 
> Mark.

thank you very much for your explanation, I get it now! :-)


Best

Klaus

--
Klaus Major
http://www.major-k.de
klaus at major-k.de



More information about the use-livecode mailing list