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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:41:35+00:00 2026-06-15T18:41:35+00:00

For example I have several decimals: decimal[] arr = { 1, (decimal)1.1, (decimal)1.00 };

  • 0

For example I have several decimals:

decimal[] arr = { 1, (decimal)1.1, (decimal)1.00 };

they represent price in russian rubles:

var overrideCulture = new System.Globalization.CultureInfo("ru-RU");

when I use:

foreach (var d in arr)
{
     string s = d.ToString("c", overrideCulture);
     Console.WriteLine(s);
}

I get

1,00p.
1,10p.
1,00p.

as result, but what I need is, if fraction is zero, I don’t want it to be displayed but I need to keep currency format. in this example I want to get:

1p.
1,10p.
1p.

I can simply get of fractions like:

foreach (var d in arr)
{
     string s = d.ToString("#.##", overrideCulture);
     Console.WriteLine(s);
}

but currency format will be lost.

string s = d.ToString("#.##c", overrideCulture);

also does’n work, I get 1c or 1,1c

Is there some NOT tricky way to get such formatting like I need?

  • 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-15T18:41:36+00:00Added an answer on June 15, 2026 at 6:41 pm

    I don’t know of a single format string that will do that but one way would be:

    string format = (d == Math.Round(d,0)) ? "c0" : "c";
    string s = d.ToString(format, overrideCulture);
    

    if d may have more than 2 decimal places and you want to not show decimals for any value that would round to .00 try

    string format = (Math.Round(d,2) == Math.Round(d,0)) ? "c0" : "c";
    string s = d.ToString(format, overrideCulture);
    

    As a side note you can avoid a cast be defining the constants as decimal literals:

    decimal[] arr = { 1m, 1.1m, 1.00m };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several sites in different domains: example.com , example.org , mail.example.com and passport.example.org
I have several delimiters. For example {del1, del2, del3 }. Suppose I have text
There have been several questions posted to SO about floating-point representation. For example, the
I have been searching several days for an example of how to make a
I have made modifications to several example OpenCV projects within Android, however I am
I have a function that updates several tables. As an example, let's say it
I have an application with several windows/views that show the same object. For example
I have a table, for example, mytable. It has several columns: col1, col2, col3.
I have a div <div id=masterdiv> which has several child <div> s. Example: <div
I have several elements in my web page generated by JavaScript. Here's an example

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.