Source language: Translate to:

Format variable into currency

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Format variable into currency

Postby smartmedia » Thu Dec 10, 2009 11:57 am

Hi..

I need to make calculation with some variables and i want the result to be formated in currency.
1) Do i need to convert the variable to plain numbers before i calculate them..?
2) There is any command to make the transformation automatic...???
For example:
My 1 item price is 23081,90 € my 2 item price 5400 normally i must get 28481,90 How i will get 28.481,90

Thanks

PS. I think this future must be added to math function.
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Neosoft Support » Thu Dec 10, 2009 12:42 pm

All you need to do is remove the currency symbol and the thousands separator. For example:

In Europe:

StrReplace "[Price]" "€" "" "[Price]" ""
StrReplace "[Price]" "." "" "[Price]" ""
Math...

Or in the United States:

StrReplace "[Price]" "$" "" "[Price]" ""
StrReplace "[Price]" "," "" "[Price]" ""
Math...

I think this future must be added to math function.


I'll add it to the list.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby smartmedia » Thu Dec 10, 2009 2:31 pm

Hi..

Dave,

My problem is not the € or $ symbol. Is the formating in numbers. Iwant when i math 100000+2300,39 to have as result in variable this 102.300,39 with exactly format.
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Neosoft Support » Fri Dec 11, 2009 10:56 am

How about a VBScript function:

Code: Select all
{NeoBook Function}
Version=5.60
Language=VBScript
Param=[%1]|Number|Number to be formatted:
Param=[%2]|Variable|Variable to store result:
{End}
publication.nbSetVar "[%2]", FormatCurrency([%1])
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby smartmedia » Sat Dec 12, 2009 4:33 am

Hi..

Dave,
I tried this, but it doesn't seem to work right. I gave the number 27395,51 and has returned
27.395,000000000000000000000000000000000000000000000000000 € with the € symbol inside.
Looking in internet i found this page http://www.w3schools.com/VBscript/func_formatcurrency.asp but i didn't find any solution.

Any ideas...???
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Gaev » Sat Dec 12, 2009 7:17 am

smartmedia:

On the W3schools page it clearly shows that the function has a number of optional parameters ... after the input value, the next one is ...
NumDigAfterDec
Indicates how many places to the right of the decimal are displayed. Default is -1 (the computer's regional settings are used)

You specified 27395,51 ... which tells vbscript that you want 51 decimal places ... and that is exactly what it returned.


Try entering 27395.51 for the expression.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby smartmedia » Sat Dec 12, 2009 8:32 am

Gaev wrote:smartmedia:

On the W3schools page it clearly shows that the function has a number of optional parameters ... after the input value, the next one is ...
NumDigAfterDec
Indicates how many places to the right of the decimal are displayed. Default is -1 (the computer's regional settings are used)

You specified 27395,51 ... which tells vbscript that you want 51 decimal places ... and that is exactly what it returned.


Try entering 27395.51 for the expression.


I tried that Gaev and simply the script is show up error execution. I tried FormatCurrency([%1],-1) without luck
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Gaev » Sat Dec 12, 2009 9:29 am

smartmedia:

I am not sure about VBScript in non-English versions ... but over here, I tried 2 cases ... and they worked.

a) With the script "as provided by Dave" ... I passed 40.23 ... and it returned $40.23

b) I modified the NeoBook Function to have 3 parameters ... and the command to be ...

Code: Select all
publication.nbSetVar "[%2]", FormatCurrency([%1],[%3])


... and then passed an explicit value for [%3] ... and it worked too ... e.g. passing 14.123456 ... and asking to return 3 decimals ($14.123) as well as 7 decimals ($14.1234560).

So you will have to define your NeoBook Function to have as many parameters as you need to pass to the VBScript command ... and you will need to pass unformatted data something like 123456.70 ... no separators for "thousanths etc." ... and dot/point for "decimal separator"
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby David de Argentina » Sat Dec 12, 2009 10:23 am

Hi SmartMedia,

Did you try NeoFormatNum ?

The link is:

http://www.neosoftware.com/neobook/modu ... d=9&lid=54

My devaluated cent,
David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Postby smartmedia » Mon Dec 14, 2009 7:58 am

Hi..

Gaev, i tried with the third parameter but i receive error execution.
The plugin is not working as i want since i must declare from the beginning the length of the numbers will used.. Nice try but still my problem is unsold.
Thanks both of you...
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Gaev » Mon Dec 14, 2009 8:28 am

smartmedia:
i tried with the third parameter but i receive error execution.
a) Did you make sure that the value you pass in [%1] contains a dot (not comma) as the decimal separator ... and no separator for the thousands, millions etc. ? e.g.

12345.67

b) Try and invoke the function using hard-coded (inline) values first ... instead of specifying variables as input ... that way you can be sure of what is being passed to the vbscript function.

c) Post the full source of the function code here
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Neosoft Support » Mon Dec 14, 2009 2:42 pm

If I set my PC's regional and language options to "Greek", then I get the same results as Smartmedia. What's happening is that VB interprets the decimal separator used in Greece (a comma) as a parameter delimiter. As Gaev pointed out this causes VB to return a result with 51 decimal places.

To solve the problem, simply enclose the number passed to the function in quotes. For example:

Call "Format Currency" "[#34][Number][#34]" "[Result]"
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby smartmedia » Tue Dec 15, 2009 1:43 am

Hi..

Thanks Dave,
That worked smoothly... You are the best..!!! :D :D :D
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests