For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > November 2004 > Re: php-db Digest 28 Nov 2004 16:17:01 -0000 Issue 2703









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: php-db Digest 28 Nov 2004 16:17:01 -0000 Issue 2703
Henry

2004-11-29, 3:59 pm

> ---------- Forwarded message ----------
> From: "balwantsingh" <balwantsingh@indoasian.com>
> To: <php-db@lists.php.net>
> 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com