Summation of Currency issue
hello I need your help this is a simple code of my work but it doesn't work
For example I want to subtract these two values they have (,) separator
Text1=567.45
Text2=9,876.39
Text3.Text = Format(CInt(Text2.Text) - CInt(Text1.Text), "#,##.00")
Result: 9,309.00
Which it should be : 9,308.94
How can I obtain real number?
Re: Summation of Currency issue
Change both CInt for CSng
Re: Summation of Currency issue
I'd rather use CDbl instead (safer for "bigger" values), and "#,##0.00" as Format (Note the 0 before the dot)
Re: Summation of Currency issue
"#,#0.00" as format is better. Note that repeating #'s is not needed per se, e.g. "#,#######0.00" works the same as with single #
cheers,
</wqw>
Re: Summation of Currency issue
and, OP, you see why? You converted the .TEXT values to an INTEGER (Cint)...and INTEGERs will not have any values to the right of the last period ("."). That's why the CSng and CDbl conversions were suggested.
Re: Summation of Currency issue
Er, why not CCur()?
Code:
Text3.Text = Format$(CCur(Text1.Text) + CCur(Text2.Text), "Currency")
Re: Summation of Currency issue
lots trouble with language locals windows config at customer PC
Latin the comma is a comma, not a DOT
English is a DOT, and use commas for mills.
Using any kind of text that express textually with mills needs to match always the local language configures in windows. Not only for printing but also for inputing.
Make sure you are using Currency variables all the way (these are 64bits, did you know?). anyway.
don't hardcode any fixed string format outputing when using format$()
also if saving values in string format inside files that can travel to others computers which has not setup the same windows language, when loading the file and converting it back to Currency variables, it can load up values wrongfully, by the commented reasons. The best way to avoid troubles, is to use the standard VAL() STR$() when storing, loading, values from/to files in string format.
Re: Summation of Currency issue
Quote:
Originally Posted by
flyguille
don't hardcode any fixed string format outputing when using format$()
"#,#0.00" is not a fixed format as "." is replaced with localized floating-point and "," with localized thousands separator and the number of digits in "thousand groups" might be 3, 4 or whatever the locale uses. (That's the reason there is no need to match groups of exactly three #'s or 0's between commas.)
Btw, I highly doubt OP knows how to construct "fixed" output formats.
cheers,
</wqw>