Volkan Volkan - 4 months ago 18
PHP Question

PHP Float Price Wrong Value?

$price = $product->fiyat1 / $currency_values[0];


im trying to do this values are

$product->fiyat1 = 50,75
$currency_values[0] = 1.0000


it is turning this value 50.0000 but i need this 50.7500

Answer
<?php
  $product_fiyat1 = '50,75';
  $currency_values[0] = 1.0000;

  $number1 = floatval(str_replace(',', '.', str_replace('.', '', $product_fiyat1)));
  $number2 = floatval($currency_values[0]);


  $price = $number1 / $number2;

  echo $price;
?>
Comments