|
-
Feb 2nd, 2021, 09:16 AM
#1
Thread Starter
Lively Member
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?
-
Feb 2nd, 2021, 09:22 AM
#2
Re: Summation of Currency issue
Change both CInt for CSng
-
Feb 2nd, 2021, 10:17 AM
#3
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)
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 2nd, 2021, 10:56 AM
#4
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>
-
Feb 2nd, 2021, 11:04 AM
#5
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.
Sam I am (as well as Confused at times).
-
Feb 2nd, 2021, 12:19 PM
#6
Re: Summation of Currency issue
Er, why not CCur()?
Code:
Text3.Text = Format$(CCur(Text1.Text) + CCur(Text2.Text), "Currency")
Last edited by dilettante; Feb 2nd, 2021 at 12:23 PM.
-
Feb 2nd, 2021, 12:30 PM
#7
Fanatic Member
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.
Last edited by flyguille; Feb 2nd, 2021 at 12:34 PM.
-
Feb 2nd, 2021, 12:37 PM
#8
Re: Summation of Currency issue
 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>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|