Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:36:16+00:00 2026-05-12T07:36:16+00:00

I have the need to format a decimal number as currency but I do

  • 0

I have the need to format a decimal number as currency but I do not wish for any rounding to occur in the process.

For example (example culture is en-US)

Dim money = 1234.556789D
money.ToString("C") ' Yields $1,234.56 (notice the rounding & truncating)

money.ToString("C99") ' Yields $1,234.556789000000000000....0 -- close but not perfect, those trailing zeros are unwanted.

' I want something that would result in this...
money.ToString("??") ' Yields $1,234.56789

' likewise....
money = 0.1D
money.ToString("??") ' Yields $0.10  (notice that it at least matches the culture's currency format -- two decimal places)

Assuming all of the users of this application would be using en_US rules I could make that “??” be something hard-coded like “$#,##0.00################################################################” — but that makes my stomach churn. Is there a built-in way to accomplish what I’m after?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:36:16+00:00Added an answer on May 12, 2026 at 7:36 am

    Seeing that there doesn’t seem to be a built-in way of doing this, I ended up rolling my own extension method that looks like…

    Public Function ToUnroundedCurrency(ByVal value As Decimal) As String
        Dim valueAsString As String = value.ToString() ' Some loss of precision happens here, but it is not a concern.
    
        Dim decimalLocation As Integer = valueAsString.IndexOf(".")
    
        ' Get number of digits after the decimal place in the number
        Dim numberOfDecimalPlaces As Integer = 0
        If (decimalLocation > 0) Then numberOfDecimalPlaces = valueAsString.Length - decimalLocation - 1
    
        ' The currency formatter has a limit of 99 decimal places -- due to the decimal -> ToString() conversion above, this will never happen, but being defensive anyway.
        If (numberOfDecimalPlaces > 99) Then
            numberOfDecimalPlaces = 99
        ElseIf (numberOfDecimalPlaces < CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits) Then
            ' also make sure we at least have the minimum required decimal places
            numberOfDecimalPlaces = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits
        End If
    
        Return value.ToString("C" & numberOfDecimalPlaces)
    End Function
    

    I noted some negligible loss of precision. We (or anybody probably) wouldn’t be dealing with decimal values fractional enough enough to ever run into the limitations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a *.sqlite file... but I need the database in *.sl3 format? What
I have this script that works, but I need to change the format of
I have the following problem: i need to convert a decimal number to string.
I have time represented by a decimal number that I need to convert to
I need to format a number with scale of 2 decimal places. The original
I have some decimal data coming from an external service. I need to format
I have a decimal number like this: 62.000,0000000 I need to cast that decimal
I need to format a float (catchy title, he?) to 2 decimal places, but
I have a number of decimal numbers stored in a database and need to
I have the need to display a date in this format: dd/mm/yyyy. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.