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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:21:00+00:00 2026-06-17T15:21:00+00:00

Possible Duplicate: Extra leading zeros when printing float using printf? I’m trying to get

  • 0

Possible Duplicate:
Extra leading zeros when printing float using printf?

I’m trying to get the output of this C program to have placeholder zeros, as the output of this program will be used as input for another program. Right now, I’m using the following print line.

fprintf(fp1, "06 BR%d%d   %3.4f%3.4f%3.4f\n",i,d,X,Y,Z);

i = index for the loop
d = index for a second loop
X = double for a Cartesian system
Y = double for a Cartesian system
Z = double for a Cartesian system

Right now the output looks like this:

06 BR12   1.00001.00001.0000

I want it to be like the following:

06 BR0102   001.0000001.0000001.000

I know that I could just add placeholding zeros manually (if i<10, add a placeholder, etc.) but is there a more efficient way to output a placeholder zero than simply adding them in if-statements?

Thank you in advance.

  • 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-17T15:21:01+00:00Added an answer on June 17, 2026 at 3:21 pm

    You can zero pad with %08.4f, for example. Note that the first number is the entire field width, not just the number of places you want before the decimal. In your example, the 3 in %3.4 has no effect. If you want your last number to only have three decimal places, you’ll want %07.3f for that one.

    The %d formats are easier – in your case, just %02d should do it.

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

Sidebar

Related Questions

Possible Duplicate: Parse Json in php Im having a problem regarding this extra field
Possible Duplicate: Why does this Javascript code inside a non-Javascript browser have extra commenting?
Possible Duplicate: Learn Python the Hard Way Exercise 17 Extra Question(S) In this exercise
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Algorithm to rotate an image 90 degrees in place? (No extra memory)
Possible Duplicate: Reference - What does this symbol mean in PHP? I don't know
Possible Duplicate: .eof() loop not working So I have a fairly simple C++ program
Possible Duplicate: typeid() returns extra characters in g++ I learned from cplusplus.com that typeid

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.