CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2010
    Posts
    11

    Problem with decimals

    Hi!

    I have a report that show prices, like $1.33
    The problem is that it is not showing decimals correctly, it shows 1.33 like $1.00

    I checked the field format, round rules, etc. Is not that.
    I checked regional settings. Is not that either.
    I checked dll (crystal) versions.

    In db (access) the value is right. It´s a float type.

    My locale is Brazil, so, decimal separator is "," and tousand separator is "."
    (In the example above, i used dot as decimal separator just to explain).

    I´m calling the report with vb6 (sp6). In Crystal Report (designer, 8.0.1.0) the price is correctly.
    It just happens when the report is called from vb program, and not in all computers. Just a few.

    Same EXE, same RPT and same DLL, but the problem occurs.

    Code in vb6:
    sql = "SELECT ... PRE_PEDIDO_ITEM.PPIT_VLR_UNIT, PRE_PEDIDO_ITEM.PPIT_VLR_LIQ, ... " & _
    "FROM ... PRE_PEDIDO_ITEM, ... " & _
    "WHERE ... "
    Rpt.LogOnServer "p2sodbc.dll", "DRP2", "DRP2", "XXXXX", "XXXXX"
    Rpt.WindowShowRefreshBtn = True
    Rpt.WindowShowSearchBtn = 1
    Rpt.WindowShowCloseBtn = 1
    Rpt.WindowTitle = "Order"
    Rpt.WindowState = crptMaximized
    Rpt.SQLQuery = sql
    Rpt.Action = 1

    Any idea?

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Problem with decimals

    Can't you use a Currency data type?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #3
    Join Date
    Feb 2010
    Posts
    11

    Re: Problem with decimals

    It´s a legacy application that have been working for years.

    This is a recent problem, so I don´t think that change the database column type
    is the best solution. It´s a ruge impact.

    tks.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Problem with decimals

    Well, what can we do, if it's NOT the code?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Feb 2010
    Posts
    11

    Re: Problem with decimals

    Well, I thought that people in this forum could have face a problem like this.

    I think it could be something like windows hotfix conflicting with this old crystal/vb...
    and I was hoping that maybe you be experienced enough to help me, because right now,
    i´m desperate.

    I believe that this problem is less programming skill and more about experience/know how.

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Problem with decimals

    Just because it used to work, doesn't mean that a change in coding can't fix it. In addition to the Currency data type, there is also the Format() function, which can return a number in the format of your choosing.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  7. #7
    Join Date
    Feb 2010
    Posts
    11

    [SOLVED] Re: Problem with decimals

    I fixed it.

    Before I call the report I change the regional settings by code using kernel32 api.
    And change it back after the report is loaded.

    Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean

    Dim wInfo As Long
    Dim Locale As Long
    Locale = GetUserDefaultLCID()
    wInfo = SetLocaleInfo(Locale, &H16, ".")

    It still doesn´t explain why it was working in some computer and others not (they have the same regional settings configuration and same version off all software).

    But... it´s working now.

    Sometimes i think that computers is not a exact science as it should be

    tks.

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Problem with decimals

    Well done.
    But it IS an exact science. It is possibly the most exact science there is at all, being always reduced down to 0 and 1.
    However, it is possibly also a very complex and sometimes intransparent science. But always exact.

  9. #9
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Problem with decimals

    There is a saying; The nice thing about computers is that they do exactly what you tell them to do. The bad thing about computers is that they do exactly what you tell them to do.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  10. #10
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Problem with decimals

    Right.
    Last edited by WoF; February 12th, 2010 at 10:19 AM.

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

Featured