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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:23:44+00:00 2026-05-27T18:23:44+00:00

I’m trying to convert a float to a string without getting scientific (1.13E-8) style

  • 0

I’m trying to convert a float to a string without getting scientific (1.13E-8) style formatting.

I’m looking for some combination of the “F” and “R” specifiers. I want the F so that it does not use the scientific style, but I also want the R so that it uses as little space as necessary to exactly represent the number.

So given 0.000000001, the string version should be 0.000000001. Not 1E-09, and not 0.000000001000.

Is it possible to tell the system “make it fixed point, but use the minimum digits necessary to exactly specify the number”?

If not, what would a good workaround be? I was thinking: use a precision of 20 and then just hack off trailing 0’s if there’s a ‘.’ in the string. Anything better?

Edit:

Here’s the version I have been using. I was really hoping there would be a format specifier I could use to make it do this instead.

var s = f.ToString("F20");
if (s.Contains("."))
{
    s = s.TrimEnd('0').TrimEnd('.');
}
  • 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-27T18:23:45+00:00Added an answer on May 27, 2026 at 6:23 pm

    The following will display only the significant digits after the decimal point, up to 10 d.

    var format = "#0.##########";
    
    string.Format(1.23, format);
    // 1.23
    
    string.Format(1.23456, format);
    // 1.23456
    
    string.Format(1.230045, format);
    // 1.230045
    
    string.Format(1.2345678912345, format);
    // 1.2345678912
    

    The key here is that the # signifier only outputs a digit if it is significant.

    Hopefully that goes some way towards what you want, at least. If not, you can always write a custom IFormatProvider.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace

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.