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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:51:31+00:00 2026-06-06T11:51:31+00:00

In a C++ code I have a matrix of double variables which I print

  • 0

In a C++ code I have a matrix of double variables which I print out. However because all of them have different number of digits, the output format is destroyed. One solution is to do
cout.precision(5) but I want different columns have a different precision. Also, because there are negative values in some cases, the presence of the - sign also causes problems. How to get around this and produce a properly formatted output?

  • 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-06T11:51:33+00:00Added an answer on June 6, 2026 at 11:51 am

    Off the top of my head, you can use setw(int) to specify the width of the output.

    like this:

    std::cout << std::setw(5) << 0.2 << std::setw(10) << 123456 << std::endl;
    std::cout << std::setw(5) << 0.12 << std::setw(10) << 123456789 << std::endl;
    

    gives this:

        0.2    123456
       0.12 123456789
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code base, in which for Matrix class, these two definitions are
I have code for a matrix multiplication lab using double[,] and I wanted to
I have a piece of code which performs calculations on a matrix by iterating
I currently have the following code: type Matrix(sourceMatrix:double[,]) = let rows = sourceMatrix.GetUpperBound(0) +
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code
I have the following code to convert the type of the matrix using cv::Mat.convertTo()
I have code which has a drop down list. And when a certain option
I have a 2d matrix created with the code: for(i=0; i < size; i++)
I have a std::istream which refers to matrix data, something like: 0.0 1.0 2.0
I am writing a library for efficient number processing. I have to support different

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.