Skip to content

Convert decimal numbers #15

Closed
Closed

Description

@SanbiVN

Your code uses the CDec function, which causes an error when the system sets the Comma character as the decimal separator. In this case, you must replace the period with a comma before using the function. The Val function doesn't require this because it uses a period as the decimal separator. However, the Val function only supports a limited number of 14 decimal digits.

Activity

  1. changed the title [-]Convert decimal numbers in VBA Office 365 Windows 11[/-] [+]Convert decimal numbers[/+] on Apr 26, 2026
  2. cristianbuse commented on Apr 27, 2026

    @cristianbuse
    Owner

    @SanbiVN This repo already handles the decimal separator regardless of the regional settings. Can you provide an example of a combination of setting and code that can trigger the error? Thanks!

  3. SanbiVN commented on Apr 27, 2026

    @SanbiVN
    Author

    I've read the source code, and I don't understand how your code handles it. But it's clever; you used CStr to get the decimal separator without needing any complicated code.

    chDot = AscW(Mid$(CStr(1.1), 2, 1))

    The code I usually use to handle the decimal separator is:

    IIF("1.1" = 1.1,".",",")

    Thank you. LibJson is quite powerful for parsing JSON.

  4. cristianbuse commented on Apr 27, 2026

    @cristianbuse
    Owner

    Thank you for the kind words!

    Just a note, because you mentioned the Val method. Unfortunately Val would lose precision for Decimal and would only retain precision for Double values. As a bonus, the adopted method is also faster than using Val.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions