RE: [PHP] decimal point movement...

From: Date: Thu, 18 Jan 2001 22:08:58 +0000
Subject: RE: [PHP] decimal point movement...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35463@lists.php.net to get a copy of this message
cuz i didn't know it existed ;) my point is that math should be used instead of a regex as it is more efficient. DanO -----Original Message----- From: jeremy brand [mailto:jeremy@nirvani.net] Sent: Thursday, January 18, 2001 2:06 PM To: DanO Cc: Php-General@Lists. Php. Net Subject: RE: [PHP] decimal point movement... If you want to use the modulus, why not just use modulus (%) ? But, instead of doing all that math, why not just use the number_format() function? Jeremy Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: jeremy@nirvani.net http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "LINUX is obsolete" -- Andy Tanenbaum, January 29th, 1992 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://www.JEEP-FOR-SALE.com/ -- I need a buyer Get your own Free, Private email at http://www.smackdown.com/ On Thu, 18 Jan 2001, DanO wrote: > Date: Thu, 18 Jan 2001 13:57:55 -0800 > From: DanO <dano@informano.net> > To: "Php-General@Lists. Php. Net" <php-general@lists.php.net> > Subject: RE: [PHP] decimal point movement... > > > why go thru the costly overhead of a regex when you can use math? > > > ex: > > <? > $number = '600'; > $new = $number/100; > $rem = $new-$new%100; > if ($rem == 0) { > $new .= ".00"; > } > > print $number; > print "\n"; > print $new; > ?> > > you divide the number by 100 to push the decimal back, and, if there is no > remainder (by modulus division), you append .00 to the variable. > > DanO > > -----Original Message----- > From: Robert Collins [mailto:rcollins@Insight.com] > Sent: Thursday, January 18, 2001 1:05 PM > To: 'Christopher Allen'; php > Subject: RE: [PHP] decimal point movement... > > > Christopher, > > try a regular expression somthing like this > > <? > $temp = "007170"; > ereg ("([0-9]{2})([0-9]*)", $temp, $test); > $changed_to_deicmal_form = $test[1].".".$test[2]; > echo "$changed_to_deicmal_form"; > ?> > > Robert > > -----Original Message----- > From: Christopher Allen [mailto:callen@driver8.org] > Sent: Thursday, January 18, 2001 11:35 AM > To: php > Subject: [PHP] decimal point movement... > > > > Greetings! > > I am looking for an efficeient way to assign a decimal to a number and store > the new number. > I wanto add a decimal point after the first 2 leading digitis.. > while ( query runs) > { > > $temp=007170; > $changed_to_deicmal_form; // would store .7170 > } > > Furthermore I was using printf to round up numbers...has anyone found a > different or better way? > > > > > > Christopher C. M. Allen > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#35463) next »