Author Topic: Solved--Convert product price to integer value?  (Read 1919 times)

panthe

  • Beginner
  • *
  • Posts: 6
Solved--Convert product price to integer value?
« on: October 01, 2009, 19:16:13 pm »
Hi everyone,
I'm don't know PHP and I want put in my flypage a simple calc that show an integer value.
This value is the 10% of product price.
For example:

€ 29,08 = 2
€ 29,58 = 2
€ 29,98 = 2

I have try putting this code on flypage but is wrong
<?php
echo ($product_price * 0.1)
?>

Scuse be for a stupid question but I don't know how can made what I need...
Thanks ;-)

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10412
  • VirtueMart Version: 3+
Re: Add a simple calc in flypage
« Reply #1 on: October 01, 2009, 20:16:58 pm »
I dont know PHP but I think you need to define the .1 before your multiply, and then echo

I just took this of another site, and plugged numbers in

<?php

$first_number = $product_price;
$second_number = .1;
$sum_total = $second_number * $first_number;

echo ($sum_total);

?>
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

panthe

  • Beginner
  • *
  • Posts: 6
Re: Add a simple calc in flypage
« Reply #2 on: October 01, 2009, 21:57:04 pm »
Thanks for your reply and scuse me for my bad english!!!

I've just try before to insert a similar code than you've posted but don't work.

I need to convert the price into a float or double value before calculate the value.

I try with this code but don't work...

<?php
$numeric_price = str_replace("&euro;","",$product_price);
$numeric_price = str_replace(",",".",$numeric_price);
$numeric_price = str_replace(" ","",$numeric_price);
$first_number = $numeric_price;
$second_number = 0.1;
$sum_total = $second_number * $first_number;
echo ($sum_total);
?>


panthe

  • Beginner
  • *
  • Posts: 6
Re: Add a simple calc in flypage
« Reply #3 on: October 06, 2009, 15:05:00 pm »
I need to convert $product_price in an integer value...
Someone can help me?

panthe

  • Beginner
  • *
  • Posts: 6
Re: Convert product price to integer value? [SOLVED]
« Reply #4 on: October 06, 2009, 16:57:00 pm »
ok, I've found the correct way to operate.
$product_price contains HTML Tags too and before to operate with the value I need to delete this tags with this command strip_tags()

<?php

$replacing   = array('\r\n', '\n', '\r','&euro',';');

$numeric_price = trim((string) $product_price);
$numeric_price = str_replace($replacing, '', $numeric_price);

$numeric_price = str_replace(',', '.', $numeric_price);

$numeric_price = strip_tags($numeric_price);      

$first_number = $numeric_price;
$second_number = 0.1;
$sum_total = $second_number * $first_number;      

echo (int) $sum_total;      
?>

panthe

  • Beginner
  • *
  • Posts: 6
Re: Convert product price to integer value?
« Reply #5 on: October 06, 2009, 16:57:39 pm »
ok, I've found the correct way to operate.
$product_price contains HTML Tags too and before to operate with the value I need to delete this tags with this command strip_tags()

<?php

$replacing   = array('\r\n', '\n', '\r','&euro',';');

$numeric_price = trim((string) $product_price);
$numeric_price = str_replace($replacing, '', $numeric_price);

$numeric_price = str_replace(',', '.', $numeric_price);

$numeric_price = strip_tags($numeric_price);      

$first_number = $numeric_price;
$second_number = 0.1;
$sum_total = $second_number * $first_number;      

echo (int) $sum_total;      
?>