- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm converting some old Fortran code and need toadd some leading zeroes to a character string. What I need to accomplish is:
I always need my numer(1-999) to have 3 character digits.
1 should be 001
50 should be 050
999 should be 999
My old code had the following internal write:
write(charNUM,"(B'###')")NUM
IVF doesn't allow this. My solution was to do the following:
IF(NUM.LT.10)THEN
WRITE(CHARNUM,'(I3)')NUM
CHARNUM='00'//TRIM(ADJUSTL(CHARNUM))
ELSE IF(NUM.LT.100)THEN
WRITE(CHARNUM,'(I3)')NUM
CHARNUM='0'//TRIM(ADJUSTL(CHARNUM))
END IF
There must be a cleaner solution than this. Any thoughts?
Thanks,
Ernie P.
I'm converting some old Fortran code and need toadd some leading zeroes to a character string. What I need to accomplish is:
I always need my numer(1-999) to have 3 character digits.
1 should be 001
50 should be 050
999 should be 999
My old code had the following internal write:
write(charNUM,"(B'###')")NUM
IVF doesn't allow this. My solution was to do the following:
IF(NUM.LT.10)THEN
WRITE(CHARNUM,'(I3)')NUM
CHARNUM='00'//TRIM(ADJUSTL(CHARNUM))
ELSE IF(NUM.LT.100)THEN
WRITE(CHARNUM,'(I3)')NUM
CHARNUM='0'//TRIM(ADJUSTL(CHARNUM))
END IF
There must be a cleaner solution than this. Any thoughts?
Thanks,
Ernie P.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WRITE (charNUM,'(I3.3)') NUM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... and standard conforming, unlike whatever it was you were using (never saw that extension before.)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page