1

we are using this code for displaying shipping charges in magneto site :

<?php echo "Selling Price + " . $_excl . " Delivery "; ?>

where $_excl will return the value.

its displaying results as 10.00, 20.00...etc.

I want to remove .00 from "10.00" & display only 10.

I checked here1 & here2

I tried below codes :

echo "Selling Price + " . round($_excl,0) . " Delivery ";
echo "Selling Price + " . round($_excl) . " Delivery ";
echo "Selling Price + " . $_excl + 0 . " Delivery ";

nothing worked for me, Please give me updated code for this

Community
  • 1
  • 1
fresher
  • 917
  • 2
  • 20
  • 55

4 Answers4

2

You can either use (int), number_format() or round() or intval()

$num = '10.00';
echo (int)$num ."\n"; //print 10
echo number_format($num,0) ."\n"; //print 10
echo round($num,0) ."\n"; // print 10
echo intval($num) ."\n"; // print 10

live sample

So in your case

echo "Selling Price + " . (int)$_excl . " Delivery "  .  "\n";
echo "Selling Price + " . number_format($_excl,0) . " Delivery "  .  "\n";
echo "Selling Price + " . round($_excl,0) . " Delivery "  .  "\n";
echo "Selling Price + " . intval($_excl) . " Delivery "  .  "\n";

live sample

Fabio
  • 23,183
  • 12
  • 55
  • 64
1

You can use number_format():

echo "Selling Price + " . number_format($_excl, 0) . " Delivery ";
Mawia HL
  • 3,605
  • 1
  • 25
  • 46
1

$num + 0 does the trick.

echo 125.00 + 0; // 125
echo '125.00' + 0; // 125
echo 966.70 + 0; // 966.7

Internally, this is equivalent to casting to float with (float)$num or floatval($num) but I find it simpler.

Update

echo "Selling Price + " . ($_excl + 0) . " Delivery ";
Ali Zia
  • 3,825
  • 5
  • 29
  • 77
1

Try

echo "Selling Price + " . (int)$_excl . " Delivery ";

eg

$f = "10.00";
echo (int)$f; //gives 10

hope it hepls :)

FastTurtle
  • 1,747
  • 11
  • 15