Hey All,

  I have a form that collects fee amounts for a product.  Some fees for this product can be manually entered by the user.  My problem is that I use these numbers for calculations, but of course I could not compute with strings.  After searching on the net for a way to convert strings to numbers, the most common solution was to create a new variable, with a 'int' datatype.  The problem with this method is that if user entered anything as a decimal, every decimal value gets ignored.

Example
23.25 as a string ===23 as a number

Is there a way that I can convert these strings into numbers and maintain the decimals so that I can make calculations?

Thanks for the help!

    php will treat strings as numbers

    	$a=(string)1;
    	$b=(string)2;
    
    echo $a + $b;
    
    //output 3
    

    could cast them as float

    check out Type Juggling

    if your still have issues, please post some examples.

    if your putting 23.23 in a db make sure its not an int

      u dont worry about data types in php use any variable as u like

        Write a Reply...