如何获取字符串中小数点前后的值

My PHP file receives (via $_POST) strings (with constant prefix) like:

(constant prefix in this example = 'astring'; figure before and after the decimal point can vary in size)

  • astring1.1
  • astring1.2 ..
  • astring23.2
  • astring23.6

How to get the value behind the decimal point? I know how to extract the total figure from the constant prefix, but I need to use the figures before and after the decimal point and don't know how to extract those. Using preg_match in some way?

Try with explode like

$str = 'astring23.2'; 
$str_arr = explode('.',$str);
echo $str_arr[0];  // Before the Decimal point
echo $str_arr[1];  // After the Decimal point
list($before, $after) = explode(".", $string);

echo "$before is the value before the decimal point!";
echo "$after is the value after the decimal point!";

A simple way (php 5.3+):

$str = 'astring23.2';
$pre = strstr($str, '.', true);

Do you want something similar?

    <?php
        $string = "astring23.6";
        $data = explode("astring", $string);    // removed prefix string "astring" and get the decimal value            
        list($BeforeDot, $afterDot)=explode(".", $data[1]); //split the decimal value   
        echo "BeforeDot:".$BeforeDot." afterDot: ".  $afterDot;

    ?>

If you want only numbers, use like this

$str = 'astring23.2'; 
$str_arr = explode('.',$str);
echo preg_replace("/[a-z]/i","",$str_arr[0]);  // Before the Decimal point
echo $str_arr[1]; // After decimal point

If you want the number before the decimal. Try This.

$number = 2.33;
echo floor($number);