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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:11:23+00:00 2026-06-10T19:11:23+00:00

Possible Duplicate: Engineering notation in C#? Whether a metric prefix is preferable to the

  • 0

Possible Duplicate:
Engineering notation in C#?

Whether a metric prefix is preferable to the scientific notation may be up for debate but i think it has its use-cases for physical units.

I had a look around but it seems .NET does not have anything like that built in, or am i mistaken about that? Any method of achieving that would be fine.

As a clarification: The goal is to display any given number as a floating point or integer string with a value between 1 and 999 and the respective metric prefix.

e.g.

1000 -> 1k
0.05 -> 50m

With some rounding:

1,436,963 -> 1.44M

  • 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-10T19:11:24+00:00Added an answer on June 10, 2026 at 7:11 pm

    Try this out. I haven’t tested it, but it should be more or less correct.

    public string ToSI(double d, string format = null)
    {
        char[] incPrefixes = new[] { 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' };
        char[] decPrefixes = new[] { 'm', '\u03bc', 'n', 'p', 'f', 'a', 'z', 'y' };
    
        int degree = (int)Math.Floor(Math.Log10(Math.Abs(d)) / 3);
        double scaled = d * Math.Pow(1000, -degree);
    
        char? prefix = null;
        switch (Math.Sign(degree))
        {
            case 1:  prefix = incPrefixes[degree - 1]; break;
            case -1: prefix = decPrefixes[-degree - 1]; break;
        }
    
        return scaled.ToString(format) + prefix;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Protect .NET code from reverse engineering? we just develop a application with
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: CompilerServices.Operators equivalent on C# I was looking for Microsoft.CSharp.CompilerServices.Operators but couldn't find
Possible Duplicate: Protect .NET code from reverse engineering? I want to make my software
Possible Duplicate: git - removing a file from source control (but not from the
Possible Duplicate: Is it possible to show numbers in non-engineering format in Matlab? am
Possible Duplicate: Why might a System.String object not cache its hash code? I always
Possible Duplicate: Detect inside Android Browser or WebView i want to detect whether the
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP

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.