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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:55:46+00:00 2026-06-18T00:55:46+00:00

I have some decimal numbers that I need to write to a text file

  • 0

I have some decimal numbers that I need to write to a text file with leading zeros when appropriate. I’ve done some research on this, and everything I’ve seen suggests something like:

  REAL VALUE
  INTEGER IVALUE

  IF (VALUE.LT.0) THEN
    IVALUE = CEILING(VALUE)
  ELSE
    IVALUE = FLOOR(VALUE)
  ENDIF
  WRITE(*,1) IVALUE, ABS(VALUE)-ABS(IVALUE)
1 FORMAT(I3.3,F5.4)

As I understand it, the IF block and ABS parts should allow this to work for all values on -100 < VALUE < 1000. If I set VALUE = 12.3456, the code above should produce “012.3456” as the output, and it does. However if I have something like VALUE = -12.3456, I’m getting “(3 asterisks).3456” as my output. I know the asterisks usually shows up when there are not enough characters provided for in the FORMAT statement, but 3 should be enough in this example (1 character for the “-” and two characters for “12”). I haven’t tested this yet with something like VALUE = -9.876, but I’d expect the output to be “-09.8760”.

Is there something wrong in my understanding of how this works? Or is there some other limitation of this technique that I’m violating?

UPDATE: Okay I’ve looked into this some more, and it seems to be a combination of a negative value and the I3.3 format. If VALUE is positive and I have the I3.3, it will put leading zeros as expected. If VALUE is negative and I only have I3 as my format, I get the correct value output, but it will be padded with spaces before the negative sign instead of padded with zeros after the negative (so -9.8765 is output as ” -9.8765″, but that leading space breaks what I’m using the .txt file for, so it’s not acceptable).

  • 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-18T00:55:48+00:00Added an answer on June 18, 2026 at 12:55 am

    Tho problem is with your integer data edit descriptor. With I3.3 you require at least 3 digits and the field width is only 3. There is no place for the minus sign. Use I4.3 or, In Fortran 95 and above, I0.3.

    Answer to your edit: Use I0.3, it uses the minimum number of characters necessary.

    But finally, you just probably want this: WRITE(*,'(f0.3)') VALUE

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

Sidebar

Related Questions

I have some Decimal instances in Python. I wish to format them such that
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
Possible Duplicate: Converting decimal to binary in Java I have found this code that
I have some decimal data coming from an external service. I need to format
I have some weird numbers such as 19 or 23. These two will need
I need some help with floating point numbers...please! Here's the thing, I have code
I have some text content (read in from the HTML using jQuery) that looks
I have written some general functions to convert between decimal and any other base-n
I have some data loaded as a np.ndarray and need to convert it to
I have some arbitrary pixel data that I want to save as a PNG.

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.