printf question

Discussion in 'Perl Misc' started by Scot, Dec 5, 2003.

  1. Scot

    Scot Guest

    Having trouble figuring out how to do this:

    Have a number, say 15109.

    How do I use printf to make it 15.109? And then 15.1 (I think this can be
    done with a %f printf)?

    Thanks,

    Scott
     
    Scot, Dec 5, 2003
    #1
    1. Advertising

  2. Scot

    Tony Curtis Guest

    >> On Fri, 5 Dec 2003 10:21:05 -0500,
    >> "Scot" <> said:


    > Having trouble figuring out how to do this: Have a number,
    > say 15109.


    > How do I use printf to make it 15.109? And then 15.1 (I
    > think this can be done with a %f printf)?


    Do you mean: as in some European locales where "." is used to
    separate digits in large numbers like "," does in English?

    Or do you want to perform arithmetic operations (division) on
    the value, then output the value to a certain precision?

    hth
    t
     
    Tony Curtis, Dec 5, 2003
    #2
    1. Advertising

  3. Scot

    Scot Guest

    Hi Tony,

    it will be representing the decimal in and English number. so i want to
    move it over a certain number of spaces to the left, in this example, it
    would move two spaces to the left...then have everything but one number to
    the right chopped off.

    Thanks,

    Scott
    "Tony Curtis" <tony_curtis32@_SPAMTRAP_yahoo.com> wrote in message
    news:...
    > >> On Fri, 5 Dec 2003 10:21:05 -0500,
    > >> "Scot" <> said:

    >
    > > Having trouble figuring out how to do this: Have a number,
    > > say 15109.

    >
    > > How do I use printf to make it 15.109? And then 15.1 (I
    > > think this can be done with a %f printf)?

    >
    > Do you mean: as in some European locales where "." is used to
    > separate digits in large numbers like "," does in English?
    >
    > Or do you want to perform arithmetic operations (division) on
    > the value, then output the value to a certain precision?
    >
    > hth
    > t
     
    Scot, Dec 5, 2003
    #3
  4. Scot wrote:
    > "Tony Curtis" wrote


    >>>>"Scot" <> said:

    >>
    >>>Having trouble figuring out how to do this: Have a number,
    >>>say 15109.

    >>
    >>>How do I use printf to make it 15.109? And then 15.1 (I
    >>>think this can be done with a %f printf)?

    >>
    >>Do you mean: as in some European locales where "." is used to
    >>separate digits in large numbers like "," does in English?
    >>
    >>Or do you want to perform arithmetic operations (division) on
    >>the value, then output the value to a certain precision?

    >
    > Hi Tony,
    >
    > it will be representing the decimal in and English number.
    > so i want to move it over a certain number of spaces to the
    > left, in this example, it would move two spaces to the
    > left...then have everything but one number to the right
    > chopped off.


    perl -e "printf('%.1f',(1509/100))"
    15.1

    Adjust to taste..

    HTH

    Simon.
     
    Simon Andrews, Dec 5, 2003
    #4
  5. Scot

    Scot Guest

    Thanks Simon. I just came across an idea from someone that i might use that
    is similar where i will use length() to adjust the number of 0's that i use
    in the division.

    Thanks,

    Scott
    "Simon Andrews" <> wrote in message
    news:bqqbkr$450$...
    > Scot wrote:
    > > "Tony Curtis" wrote

    >
    > >>>>"Scot" <> said:
    > >>
    > >>>Having trouble figuring out how to do this: Have a number,
    > >>>say 15109.
    > >>
    > >>>How do I use printf to make it 15.109? And then 15.1 (I
    > >>>think this can be done with a %f printf)?
    > >>
    > >>Do you mean: as in some European locales where "." is used to
    > >>separate digits in large numbers like "," does in English?
    > >>
    > >>Or do you want to perform arithmetic operations (division) on
    > >>the value, then output the value to a certain precision?

    > >
    > > Hi Tony,
    > >
    > > it will be representing the decimal in and English number.
    > > so i want to move it over a certain number of spaces to the
    > > left, in this example, it would move two spaces to the
    > > left...then have everything but one number to the right
    > > chopped off.

    >
    > perl -e "printf('%.1f',(1509/100))"
    > 15.1
    >
    > Adjust to taste..
    >
    > HTH
    >
    > Simon.
    >
     
    Scot, Dec 5, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edith Gross
    Replies:
    2
    Views:
    342
    =?iso-8859-1?Q?Juli=E1n?= Albo
    Nov 2, 2003
  2. ben
    Replies:
    4
    Views:
    623
    Martin Ambuhl
    Jun 26, 2004
  3. whatluo

    (void) printf vs printf

    whatluo, May 26, 2005, in forum: C Programming
    Replies:
    29
    Views:
    1,249
  4. azza

    printf affects following printf/s

    azza, Oct 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    433
  5. guru
    Replies:
    8
    Views:
    284
Loading...

Share This Page