RE: [PHP] Formating Numbers

2009-04-25 Thread Warren Vail
As an alternative you might consider;

$number = sprintf("%01.2f",$number);  

There was a time many years ago you had to be careful doing math with
floats. Test, test and test some more.

Warren 

> -Original Message-
> From: kranthi [mailto:kranthi...@gmail.com] 
> Sent: Saturday, April 25, 2009 8:38 PM
> To: Gary
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Formating Numbers
> 
> pl post the desired result, the functions
> 
> if u r trying to get $ 34,567.25
> i dont understand y this is not working for u...
> http://php.net/manual/en/function.number-format.php#88486
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Formating Numbers

2009-04-25 Thread kranthi
pl post the desired result, the functions

if u r trying to get $ 34,567.25
i dont understand y this is not working for u...
http://php.net/manual/en/function.number-format.php#88486

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] formating numbers & date

2002-12-04 Thread Jeff Bluemel
worked great...

the other method may be a little quicker, but this code is easier for me to
understand, and although it is used in a loop there really is no visible
difference in how quickly it displays.

thanks,

Jeff
"Justin French" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> on 05/12/02 11:15 AM, Justin French ([EMAIL PROTECTED]) wrote:
>
> > Hi,
> >
> >  > $date = '2002-12-04 23:21:49';
> > $newdate = date('m/d/Y', strtotime($date));
> > echo $newdate;
> > ?>
>
> Whooops, forgot the time bit!
>
> Should be
>
>  $date = '2002-12-04 23:21:49';
> $newdate = date('n/j/Y g:i:s a', strtotime($date));
> echo $newdate;
> ?>
>
> echo's 12/4/2002 11:21:49 pm
>
> also fixed the leading zero's problem :)
>
>
> Justin French
> 
> http://Indent.com.au
> Web Development &
> Graphic Design
> 
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Justin French
on 05/12/02 12:47 PM, Rick Widmer ([EMAIL PROTECTED]) wrote:

> Yes, it is simpler to code, but it also takes almost twice as long to run.
> 
> 1000 iterations with strtotime: 0.2296 seconds
> 1000 iterations with substr:0.1308 seconds
> 
> Doesn't matter much if you only do it once, but it can add up in a loop.

very good point :)

Justin French

http://Indent.com.au
Web Development & 
Graphic Design



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Rick Widmer
At 11:51 AM 12/5/02 +1100, Justin French wrote:

on 05/12/02 11:37 AM, Rick Widmer ([EMAIL PROTECTED]) wrote:

> $Hour = substr( $Date, 11, 2 );
> if( $Hour ) > 12 {
> $Hour = $Hour - 12;
> $AMPM = 'PM';
> }
>
> else {
> $AMPM = 'AM';
> }
>
> echo substr( $Date, 5, 2 ), '/', substr( $Date, 8, 2 ), '/',
> substr( $Date, 0, 4 ), ' ', $Hour, substr( $Date, 13, 6 ), $AMPM;

Isn't this a little simpler?



There's always more than one way to do something I guess :)



Yes, it is simpler to code, but it also takes almost twice as long to run.

1000 iterations with strtotime: 0.2296 seconds
1000 iterations with substr:0.1308 seconds

Doesn't matter much if you only do it once, but it can add up in a loop.

Rick



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Jeff Bluemel
thanks...

I will play with this, and let ya know if I have a problem...  looks easy
enough.

Jeff
"Justin French" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> on 05/12/02 11:15 AM, Justin French ([EMAIL PROTECTED]) wrote:
>
> > Hi,
> >
> >  > $date = '2002-12-04 23:21:49';
> > $newdate = date('m/d/Y', strtotime($date));
> > echo $newdate;
> > ?>
>
> Whooops, forgot the time bit!
>
> Should be
>
>  $date = '2002-12-04 23:21:49';
> $newdate = date('n/j/Y g:i:s a', strtotime($date));
> echo $newdate;
> ?>
>
> echo's 12/4/2002 11:21:49 pm
>
> also fixed the leading zero's problem :)
>
>
> Justin French
> 
> http://Indent.com.au
> Web Development &
> Graphic Design
> 
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Justin French
on 05/12/02 11:37 AM, Rick Widmer ([EMAIL PROTECTED]) wrote:

> $Hour = substr( $Date, 11, 2 );
> if( $Hour ) > 12 {
> $Hour = $Hour - 12;
> $AMPM = 'PM';
> }
> 
> else {
> $AMPM = 'AM';
> }
> 
> echo substr( $Date, 5, 2 ), '/', substr( $Date, 8, 2 ), '/',
> substr( $Date, 0, 4 ), ' ', $Hour, substr( $Date, 13, 6 ), $AMPM;

Isn't this a little simpler?



There's always more than one way to do something I guess :)


Justin French

http://Indent.com.au
Web Development & 
Graphic Design



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Justin French
on 05/12/02 11:15 AM, Justin French ([EMAIL PROTECTED]) wrote:

> Hi,
> 
>  $date = '2002-12-04 23:21:49';
> $newdate = date('m/d/Y', strtotime($date));
> echo $newdate;
> ?>

Whooops, forgot the time bit!

Should be



echo's 12/4/2002 11:21:49 pm

also fixed the leading zero's problem :)


Justin French

http://Indent.com.au
Web Development & 
Graphic Design



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Rick Widmer
At 04:58 PM 12/4/02 -0700, Jeff Bluemel wrote:

I'm displaying a date that I get from a informix database query - the date
format is as follows;

2002-12-04 23:21:49

I want it to display as 12/4/2002 11:21:49 PM


$Hour = substr( $Date, 11, 2 );
if( $Hour ) > 12 {
   $Hour = $Hour - 12;
   $AMPM = 'PM';
   }

else {
   $AMPM = 'AM';
   }

echo substr( $Date, 5, 2 ), '/', substr( $Date, 8, 2 ), '/',
 substr( $Date, 0, 4 ), ' ', $Hour, substr( $Date, 13, 6 ), $AMPM;

You may need to adjust the numbers in the substrs...

Rick


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Justin French
Hi,



Should do the trick -- although I haven't stripped out the leading 0 in
either the day or month, hence it will echo 12/04/2002, not 12/4/2002.

Season to taste,

Justin




on 05/12/02 10:58 AM, Jeff Bluemel ([EMAIL PROTECTED]) wrote:

> I'm displaying a date that I get from a informix database query - the date
> format is as follows;
> 
> 2002-12-04 23:21:49
> 
> I want it to display as 12/4/2002 11:21:49 PM
> 
> Jeff
> 
> "Jason Wong" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>> On Wednesday 04 December 2002 08:29, Jeff Bluemel wrote:
>> 
>>> ... but the date format doesn't seem to
>>> allow me to pass it a date.
>> 
>> Your code?
>> 
>> --
>> Jason Wong -> Gremlins Associates -> www.gremlins.biz
>> Open Source Software Systems Integrators
>> * Web Design & Hosting * Internet & Intranet Applications Development *
>> 
>> /*
>> Information Processing:
>> What you call data processing when people are so disgusted with
>> it they won't let it be discussed in their presence.
>> */
>> 
> 
> 

Justin French

http://Indent.com.au
Web Development & 
Graphic Design



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-04 Thread Jeff Bluemel
I'm displaying a date that I get from a informix database query - the date
format is as follows;

2002-12-04 23:21:49

I want it to display as 12/4/2002 11:21:49 PM

Jeff

"Jason Wong" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Wednesday 04 December 2002 08:29, Jeff Bluemel wrote:
>
> > ... but the date format doesn't seem to
> > allow me to pass it a date.
>
> Your code?
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> Information Processing:
> What you call data processing when people are so disgusted with
> it they won't let it be discussed in their presence.
> */
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-03 Thread Jason Wong
On Wednesday 04 December 2002 08:29, Jeff Bluemel wrote:

> ... but the date format doesn't seem to
> allow me to pass it a date.

Your code?

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Information Processing:
What you call data processing when people are so disgusted with
it they won't let it be discussed in their presence.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] formating numbers & date

2002-12-03 Thread Jeff Bluemel
ok - I've been looking through this...

the number_format is working great (actually I finally found that function
right before I read your response), but the date format doesn't seem to
allow me to pass it a date.

Jeff

"Kevin Stone" <[EMAIL PROTECTED]> wrote in message
01ff01c29b0b$381e2380$6601a8c0@kevin">news:01ff01c29b0b$381e2380$6601a8c0@kevin...
> To change the number of decimal places look into the number_format()
> function.
> To change the date/time structure the date() function will do what you
need.
> Search for both on www.php.net
>
> -Kevin
>
>
> - Original Message -
> From: "Jeff Bluemel" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, December 03, 2002 1:11 PM
> Subject: [PHP] formating numbers & date
>
>
> > I'm curious how I change the number of decimal places displayed, and
also
> > changing the date / time structures before displaying them with an echo
> > command.
> >
> > Jeff
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] formating numbers

2001-08-24 Thread Jack Dempsey

Javier,

Can you provide a lil more info? What exactly are you trying to do?
Without seeing your code, its hard to guess...i'd suggest though looking
at www.php.net/number_format www.php.net/printf

jack

-Original Message-
From: Javier Bellido [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, August 25, 2001 12:23 AM
To: lista php
Subject: [PHP] formating numbers

Hi people!

I'm trying to migrate my site from perl to  PHP4. The question is how I
get numbers look like this: 0001, 0002, etc


Thanks for your time & help




Javier Bellido

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] formating numbers to two decimal points - money - best ways

2001-07-18 Thread Adrian Ciutureanu



http://php.net/number_format


> -Original Message-
> From: Tim Olsen [mailto:[EMAIL PROTECTED]]
> Sent: 18 iulie 2001 10:52
> To: [EMAIL PROTECTED]
> Subject: [PHP] formating numbers to two decimal points - money - best
> ways
> 
> 
> Anyone have functions for formatting numbers being multiplied 
> by variables 
> and whatnot to two decimal points - rounded up? As for 
> displaying total 
> cost, etc?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] formating numbers to two decimal points - money - best ways

2001-07-18 Thread David Robley

On Wed, 18 Jul 2001 17:21, Tim Olsen wrote:
> Anyone have functions for formatting numbers being multiplied by
> variables and whatnot to two decimal points - rounded up? As for
> displaying total cost, etc?

PHP has :-) have a look at the mathematical functions.

http://www.php.net/manual/en/ref.math.php

Round is probably the one you want.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   If a program is useless, it must be documented.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]