CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Format problem?

  1. #1
    Join Date
    Apr 2024
    Posts
    1

    Format problem?

    Code:
    int main() {
    	std::cout <<  std::format("{:< 8f}", .111111);
    }
    displays 0.111111 but I need .111111 (no initial 0).
    Is this possible just using format or do I need to manipulate the produced string?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,427

    Re: Format problem?

    I never used std::format, so can only guess.
    Try
    Code:
    std::format("{:< .8f}", .111111);
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,903

    Re: Format problem?

    This is a direct copy from this:
    https://cplusplus.com/forum/general/285622/
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,427

    Re: Format problem?

    Quote Originally Posted by 2kaud View Post
    This is a direct copy from this:
    https://cplusplus.com/forum/general/285622/
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured