printf question

S

Scot

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
 
T

Tony Curtis

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
 
S

Scot

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
 
S

Simon Andrews

Scot said:
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.
 
S

Scot

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

printf question 4
URGENT 1
extending printf 26
Command Line Arguments 0
Function is not worked in C 2
How works with large integers ? 0
Question on printf with %x 8
C coding a rotate function (help me pleasee) 1

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top