Results 1 to 8 of 8

Thread: Summation of Currency issue

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    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?

  2. #2

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    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

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    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>

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    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).

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  7. #7
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    928

    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.

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Summation of Currency issue

    Quote Originally Posted by flyguille View Post
    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
  •  



Click Here to Expand Forum to Full Width