Calculating numbers with currency formating

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andrew99
Posts: 11
Joined: Mon Mar 23, 2009 12:49 pm

Calculating numbers with currency formating

Post by andrew99 » Mon Jan 04, 2010 6:30 pm

Any ideas,

I've tried the following.

setProp cDisplaySepCurrency pValue
local tSepValue
if word 1 of the name of the target is not "field" then
return "Invalid target"
else if pValue is not a number then
return "Invalid value"
else
put format ("%1.0f", pValue) into pValue
put char -6 to -1 of pValue into tSepValue
put empty into char -6 to -1 of pValue
repeat while the number of chars in pValue > 0
put char -3 to -1 of pValue & comma before tSepValue
put empty into char -3 to -1 of pValue
end repeat
put "£" before tSepValue
put tSepValue into the target
end if
end cDisplaySepCurrency


then the calculation....


put the cDisplaySepCurrency of field "Purchase_Price_1" into v_Purchase_Price
put (v_Purchase_Price * 0.1) into v_Deposit
set the cDisplaySepCurrency of field "Deposit" to v_Deposit


I get just a zero value in field "Deposit" but don't know why?

Any thoughts appreciated.

Andrew

SparkOut
Posts: 2862
Joined: Sun Sep 23, 2007 4:58 pm

Re: Calculating numbers with currency formating

Post by SparkOut » Tue Jan 05, 2010 11:45 am

Hi Andrew,
I think I recognise that setProp handler ;-)
The reason it's not working in your situation is, I think, because the setProp handler intercepts the actual setting of the custom property to do some processing for the result you require. In this way Rev offers "virtual properties" that you can use where the original value passed to the handler is not stored, because the processed value is returned/handled/stored elsewhere. (ie the non-separated parameter value is volatile and the string of formatted currency characters is put in the field instead, with the numeric parameter lost.)

In the setProp handler, just before the end statement, include the line:

pass cDisplaySepCurrency

and that should allow the actual custom property to be set. You now have a visible field value with also the (naturally invisible) custom property recorded against the field object containing the original numeric value without the string separation chars, which will then be able to be interrogated and give you a value to use in setting the cDisplaySepCurrency of the other field.

I tried to explain this here: http://forums.runrev.com/phpBB2/viewtop ... 805#p12805 but I obviously didn't do a terribly good job.

HTH
SparkOut

andrew99
Posts: 11
Joined: Mon Mar 23, 2009 12:49 pm

Re: Calculating numbers with currency formating

Post by andrew99 » Tue Jan 05, 2010 5:44 pm

SparkOut,

Many thanks for this it worked like a charm. Sorry for the re-post I had forgotten I had posted the same question over a year ago...

Andrew

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”