extract integer and decimal part from mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

extract integer and decimal part from mysql

Post by jolan_lars »

Hi. can anyone help me with a PHP function where the integer and the decimal parts are extracted from a mixed number.

e.g.
$mix=123.456
$int=123
$dec=456

Thanx a lot!!!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Try this

Code: Select all

<?

function split_float($mix) {
	$split = explode(".", $mix);
	return $split;
}

$mix = 123.456;

$split = split_float($mix);

$int = $split[0]; // Integer
$dec = $split[1]; // Decimal

echo $int;
echo "<BR>";
echo $dec;

?>
Mark
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post by jolan_lars »

Exxxactly what i need. Thanx 4 d prompt response.

Regards.
Post Reply