Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > printf question

Reply
Thread Tools

printf question

 
 
Scot
Guest
Posts: n/a
 
      12-05-2003
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


 
Reply With Quote
 
 
 
 
Tony Curtis
Guest
Posts: n/a
 
      12-05-2003
>> On Fri, 5 Dec 2003 10:21:05 -0500,
>> "Scot" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Scot
Guest
Posts: n/a
 
      12-05-2003
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:(E-Mail Removed)...
> >> On Fri, 5 Dec 2003 10:21:05 -0500,
> >> "Scot" <(E-Mail Removed)> 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



 
Reply With Quote
 
Simon Andrews
Guest
Posts: n/a
 
      12-05-2003
Scot wrote:
> "Tony Curtis" wrote


>>>>"Scot" <(E-Mail Removed)> 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.

 
Reply With Quote
 
Scot
Guest
Posts: n/a
 
      12-05-2003
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" <(E-Mail Removed)> wrote in message
news:bqqbkr$450$(E-Mail Removed)...
> Scot wrote:
> > "Tony Curtis" wrote

>
> >>>>"Scot" <(E-Mail Removed)> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printf affects following printf/s azza C Programming 0 10-17-2010 09:43 AM
Extracting printf(...) from (void) printf(....) guru Perl Misc 8 02-03-2009 10:37 PM
(void) printf vs printf whatluo C Programming 29 09-08-2005 05:42 PM
bus error with printf line included, error without printf line? ben C Programming 4 06-26-2004 04:42 PM
Question about evaluating the arguments of printf (maybe OT?) Edith Gross C++ 2 11-02-2003 12:16 PM



Advertisments