×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Trying to format a string to a fixed length

Trying to format a string to a fixed length

Trying to format a string to a fixed length

(OP)
I have a quantity field that I need toend up with in a field with a length of 14 places. the field is of a format 14.4 so I tried using

CODE


$vQty = sprintf("%014.4f", $data[7]);

The error I got was because I am not allowed to have a decimal point in the result.

How can I get the resuly 00000000010000 for a quantity of 1 rather than 0000000001.0000?

RE: Trying to format a string to a fixed length

If the field is already in the format of 14.4, you could use the int function to only return the integer portion of the floating point number.

If you just need to remove the last 4 digits, you could use the substr function or a regex to return all but the last 4 digits.

There are other ways, but those should give you a place to start.

RE: Trying to format a string to a fixed length

The only way I see is

CODE

$vQty = sprintf("%014d", $data[7]*10000);
where 'd' is for unsigned numbers. You should also check that your numbers are not too large for the multiplication.

Franco
http://www.xcalcs.com : Online engineering calculations
http://www.megamag.it : Magnetic brakes for fun rides
http://www.levitans.com : Air bearing pads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close