> ---------- Forwarded message ----------
> From: "balwantsingh" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Date: Sat, 27 Nov 2004 18:07:27 +0530
> Subject: [PHP-DB] number format
> hello,
> 
> may pls. suggest me how i can retreive number before decimal and after
> decimal.
> for example 123456.7. I want to store 123456 in a variable and 7 in another.
> 
> also how can i force the user by validations so that he can only enter data
> in this format only i.e. 123456.7.
> 
> thanks
> 
> with best wishes
> balwant
> 

// Retrieve Number and Decimal Part
$num = "123456.7";
$num_part = substr($num, 0, strrpos($num, "."));
$dec_part = substr($num, strrpos($num, ".") + 1) ;

// Validation
if (preg_match("/^\d+\.\d+$/", $num)) {
   print("matched");
} else {
   print("not matched");
}


Regards,
Henry

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

Reply via email to