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 8081469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:44:16+00:00 2026-06-05T16:44:16+00:00

We’re currently using the following for creating US dollar values in our web application:

  • 0

We’re currently using the following for creating US dollar values in our web application:

string.Format("{0:C0}", dollarValue );

In this example, if dollarValue is 145, then we’ll see: $145. If it is -145, then we’ll see ($145) rather than -$145. Note that for us, dollarValue is a double, but it could be any number-type. I think.

Anyway, what I want is for it to be either $145 or -$145.

Now, according to my research, it might be possible to do this using the NumberFormatInfo class. I can’t figure out how to use it, and I can’t find any valid example. I did see this question here: C# creating a custom NumberFormatInfo to display "Free" when a currency value is $0.00 but the example from MSDN linked to from this question seems a bit different from what I really want to do.

I realize, I will need to do something of the following:

double dollarValue = -145d;
string myMoney = dollarValue.ToString( "C0", someIFormatProvider );

where someIFormatProvider is likely of type NumberFormatInfo. Now, what I’ve done is this:

NumberFormatInfo ni = new NumberformatInfo();
ni.CurrencyNegativePattern = 1; // The value 1 should mean not to use parenthesis
string myMoney = dollarValue.ToString( "C0", ni );

…and I get an “Instance is Read-Only” exception. While the “documentation” for the CurrencyNegativePattern property says you can SET and GET the value, apparently, you can’t. Also, NumberFormatInfo is a sealed class. I can’t easily create a new class based off it and override the value.

I’m at a loss as to how to deal with this. Right now, my workaround is to just negate my negative value and have a positive result that I do the string.Format(...) again. Yes, I realize there is no negative sign in front of this, but, of course, that’s easily resolved by adding a “-” in front of the result as needed.

Would someone be able to provide me with a working example of how to effectively use the NumbefFormatInfo class correctly in this situation? Thanks.

  • 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-06-05T16:44:18+00:00Added an answer on June 5, 2026 at 4:44 pm
    double dollarValue = -145d;
     System.Globalization.CultureInfo modCulture = new System.Globalization.CultureInfo("en-US");
     string mymoney = dollarValue.ToString("C", modCulture);
              MessageBox.Show(mymoney);
    

    If your Operating System current culture is en-US then you dont need the following line

    System.Globalization.CultureInfo modCulture = new System.Globalization.CultureInfo("en-US");
    

    The code will be

    double dollarValue = -145d;
    string mymoney = dollarValue.ToString("C");
    

    and If you want to do with NumberFormatInfo

    double dollarValue = -145d; 
    System.Globalization.CultureInfo modCulture = new System.Globalization.CultureInfo("en-US");
         NumberFormatInfo number = modCulture.NumberFormat;
         string mymoney = dollarValue.ToString("C", number);
    

    another way

    double dollarValue = -145d;
    System.Globalization.CultureInfo modCulture = new System.Globalization.CultureInfo("en-US");
    NumberFormatInfo number = modCulture.NumberFormat;
    string mymoney = dollarValue.ToString(String.Format("C",number));
    Console.WriteLine(mymoney);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.