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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:37:53+00:00 2026-05-24T23:37:53+00:00

Is it possible to format string in scientific notation in the following ways: set

  • 0

Is it possible to format string in scientific notation in the following ways:

  • set fixed places in exponent: 1

  • set fixed decimal places in mantissa: 0

     double number = 123456.789
    

So the number should be formated

  1e+5

I am not able to set 0 decimal points for mantissa:

cout.precision(0);
cout << scientific << number;

result:

1.234568e+005
  • 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-24T23:37:53+00:00Added an answer on May 24, 2026 at 11:37 pm

    I’m not sure what C++ compiler you’re using that’s giving you 3 digits for the exponent—the C and C++ standards require a minimum of 2 digits for that, and that’s what g++ does. There’s no way to get only one digit using the standard C or C++ I/O functions, so you’ll have to roll your own solution. Since doing a floating-point to string conversion is a very tricky problem [PDF], I’d strongly recommend not doing that and postprocessing the result instead.

    Here’s one way to do that:

    // C version; you can rewrite this to use std::string in C++ if you want
    void my_print_scientific(char *dest, size_t size, double value)
    {
        // First print out using scientific notation with 0 mantissa digits
        snprintf(dest, size, "%.0e", value);
    
        // Find the exponent and skip the "e" and the sign
        char *exponent = strchr(dest, 'e') + 2;
    
        // If we have an exponent starting with 0, drop it
        if(exponent != NULL && exponent[0] == '0')
        {
            exponent[0] = exponent[1];
            exponent[1] = '\0';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to format a number to 2 decimal places with Smarty PHP?
Possible Duplicate: Format numbers in javascript I have a string represents a number: 3507654
Possible Duplicate: Convert from scientific notation string to float in C# Is it there
Is it possible to use the ASP.Net Range validator when the format string is
Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat?
I'm wondering if it's possible for .Net's String.Format() to split an integer apart into
Let's say I have a number (e.g. double) and transform it using some format
I know I can format strings using the String.Format() method. Is it possible to
Possible Duplicate: JavaScript equivalent to printf/string.format How can I create a Zerofilled value using
In Oracle, is it possible to match both a particular string format and an

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.