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

1
  • Please see my updated answer. Commented Mar 24, 2016 at 7:09

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

7 Comments

can you please update the answer with my code. what change i need to do for this line : echo "Selling Price + " . $_excl . " Delivery ";
its not working for me, seems i am missing somewhere. i will inform you soon.
this is strange, as you can see in my live sample its working correctly
its really strange for me too. i am working on the same.
You are just not manipulating number, you are manipulating it as a string
|
1

You can use number_format():

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

1 Comment

it displaying like this : "Selling Price + Delivery", but no values are displaying.
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 ";

6 Comments

can you please update the answer with my code. what change i need to do for this line : echo "Selling Price + " . $_excl . " Delivery ";
@Profile101, be sure to put brackets around the addition
its displaying like this : Selling Price + 0 Delivery , only 0 is returning, no correct values.
@Profile101, add brackets around the addition. See my updated answer.
Any luck @Profile101?
|
1

Try

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

eg

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

hope it hepls :)

3 Comments

its displaying like this : Selling Price + 0 Delivery , only 0 is returning, no correct values.
Check value of $_excl becuse the example works fine. se edited code
i checked it, but when i use code in question , its returning 10 as value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.