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

  • Home
  • SEARCH
  • 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 3439540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:19:21+00:00 2026-05-18T08:19:21+00:00

Is there a string format that can be used on a decimal so that

  • 0

Is there a string format that can be used on a decimal so that the following results are obtained?

123 => "123"
123.4 => "123.40"
123.45 => "123.45"
123.456 => "123.46"

In English, the number should always be displayed with exactly two decimals, except when it holds an integer value, when it should have no decimals (so no “123.00” displays are allowed).

  • 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-18T08:19:22+00:00Added an answer on May 18, 2026 at 8:19 am

    I don’t know of any such format, I’m afraid. You might need to use:

    string text = (d == (int) d) ? ((int) d).ToString() : d.ToString("N2");
    

    EDIT: The code above will only work when d is in the range between int.MinValue and int.MaxValue. Obviously you can do better than that using long, but if you want to cover the full range of decimal you’ll need something a little more powerful.

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

Sidebar

Related Questions

Are there any codes that allow for numerical formatting of data when using string.format?
Is there a format string (?) I can pass to the VB6 Format function
In the application there is a string in the following format: String elements =
Is there any way I can specify a standard or custom numeric format string
Is there a way to format a UTC time into any arbitrary string format
Is there any performance differences between string.Format and String.Format ? As far as i
I am wondering if there is a method or format string I'm missing in
Is there any way to create a new NSString from a format string like
Is there any way to format a string by name rather than position in
Is there an easy way to convert a string from csv format into a

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.