Reputation:
i have a code which fetches value from database and subtracts to give a particular value. the values are coming from the database and there is no problem with that. the code is the following:
<del>
<span class="amount">
<i class="fa fa-inr"></i>
<?php echo $getRowVenue['main_price_corporate_artist'];?>
</span>
</del>
<span>( <b><i class="fa fa-inr"></i>
<?php
$strikePrice = $getRowVenue['main_price_corporate_artist'];
$mainPrice = $getRowVenue['offer_price_corporate_artist'];
echo $offer_price = $strikePrice - $mainPrice;
?> OFF</b> )
</span>
but when the substraction is done, its not giving me exact value , instead its giving me single digit values like the following:
how can i fix this?
Upvotes: 0
Views: 126
Reputation: 41
Please convert you prices from string with comma to float
$strikePrice = floatval(str_replace(',','.',$getRowVenue['main_price_corporate_artist']));
$mainPrice = floatval(str_replace(',','.',$getRowVenue['offer_price_corporate_artist']));
It should work
Upvotes: 0
Reputation: 2438
the comma is not a valid character for 'standard' numbers, so PHP converts 13,000
to 13
and 10,000
to 10
.
You can use numfmt_parse to use your specific locale number format.
Upvotes: 1