Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Number padding... (trailing zeros'.)

Reply
Thread Tools

Number padding... (trailing zeros'.)

 
 
ThePotPlants
Guest
Posts: n/a
 
      05-23-2004
Hi

Is there a nice way of formatting a decimal to have a fixed number of
trailing zero's?
I am decimalising some data to feed into another application. The input
requires 6 decimal places.
Using sprintf I can apply various formats, like leading zero's but can't
figure out how to add trailers...

For most of my data it's not a problem, but I have a couple of oddities that
divide neatly leading me with 4 decimal places.
One example I have. After conversion I get: 0.1029 but I want 0.102900.

At the moment I am multiplying my variable by 100000 and doing a substr on
the leading 6 characters, but there must be a nicer way than this...

Any help would be much appreciated.

Pete


 
Reply With Quote
 
 
 
 
Dave Cross
Guest
Posts: n/a
 
      05-23-2004
On Sun, 23 May 2004 19:24:11 +1200, ThePotPlants wrote:

> Hi
>
> Is there a nice way of formatting a decimal to have a fixed number of
> trailing zero's?
> I am decimalising some data to feed into another application. The input
> requires 6 decimal places.
> Using sprintf I can apply various formats, like leading zero's but can't
> figure out how to add trailers...


$ perl -le 'printf "%.6f", 0.1029'
0.102900

Dave...

 
Reply With Quote
 
 
 
 
Jay Tilton
Guest
Posts: n/a
 
      05-23-2004
"ThePotPlants" <> wrote:

: Is there a nice way of formatting a decimal to have a fixed number of
: trailing zero's?

Yes.

: One example I have. After conversion I get: 0.1029 but I want 0.102900.

printf '%.6f', 0.1029

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      05-23-2004
ThePotPlants wrote:
> Is there a nice way of formatting a decimal to have a fixed number of
> trailing zero's?
> I am decimalising some data to feed into another application. The
> input requires 6 decimal places.
> Using sprintf I can apply various formats, like leading zero's but
> can't figure out how to add trailers...


Hmmm, strange.
Doesn't the second example on the sprintf perldoc page work for?

jue


 
Reply With Quote
 
ThePotPlants
Guest
Posts: n/a
 
      05-23-2004

"Dave Cross" <> wrote in message
news...
> On Sun, 23 May 2004 19:24:11 +1200, ThePotPlants wrote:
>
> > Hi
> >
> > Is there a nice way of formatting a decimal to have a fixed number of
> > trailing zero's?

> $ perl -le 'printf "%.6f", 0.1029'
> 0.102900
>
> Dave...


Thanks guys


 
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
OT: Number Nine, Number Nine, Number Nine Frisbee® MCSE 37 09-26-2005 04:06 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net 2 07-02-2004 10:35 AM
real number to 16 bit signed number hari VHDL 6 05-02-2004 04:10 PM
IE 6.0 sockets number (TCP/IP channels number) for the same Site ??? taras ASP .Net 1 04-17-2004 04:51 AM
Convert decimal number in binary number makok VHDL 1 02-23-2004 06:04 PM



Advertisments