Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:18:15+00:00 2026-05-27T16:18:15+00:00

I am trying to echo an array as a price in php, if the

  • 0

I am trying to echo an array as a price in php, if the price is for example £2.55 is comes up as £2.55, if it is £2.50 is comes up as £2.5 , how can I get it to add the zero on the end ?.

My Mysql DB field is currently set to decimal(10,2)
Many Thanks
🙂
Merry Christmas !

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

<?php 
$query = mysql_query("SELECT * FROM hqfjt_chronoforms_data_dashboard WHERE cf_id =    '1'") or die(mysql_error());
$oilprice = mysql_fetch_object($query);
 $oilpricegasoil = $oilprice->oilpricegasoil;
 $oilpricederv = $oilprice->oilpricederv;
$oilpricekero = $oilprice->oilpricekero;
?>



<tr><?php $gasoilprice = $oilpricegasoil + $row->gasoilmargin;
              $dervprice = $oilpricederv + $row->dervmargin;
              $keroprice = $oilpricekero + $row->keromargin;?>

        <td><?php echo $row->leadname; ?></td>
        <td><?php  echo $row->businessname; ?></td>
        <td><?php  echo $row->postcode; ?></td>
        <td><?php  echo $row->gasoiluser; ?></td>
        <td><?php  echo $row->dervuser; ?></td>
        <td><?php  echo $row->kerouser; ?></td>
        <td><?php echo '£'; echo $gasoilprice; ?></td>
        <td><?php echo '£'; echo $dervprice; ?></td>
        <td><?php echo '£'; echo $keroprice; ?></td>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:18:16+00:00Added an answer on May 27, 2026 at 4:18 pm

    Simple formatting

    Try the number_format function:

    <?php
      $test = 2.50;
      echo "£", number_format($test, 2); // 2 decimal places
    ?>
    

    £2.50

    • http://codepad.org/opf0j6kV

    Be careful because this will round .005 to the next highest cent, which isn’t always what you want:

    • http://codepad.org/IQvYDXnE

    If you need different rounding, try using:

    • round()
    • ceil()
    • floor()

    Money formatting

    You could also try the money_format function, though you’ll need to make sure your locale is set correctly for it to work.

    money_format('%.2n', $number); // 2 decimal points, with national currency symbol
    

    Use a function

    Either way, I recommend you push the conversion into a function, so you can reuse it throughout your code and don’t have to repeat your number formatting:

    function toCurrency($number)
    {
      return '£' . number_format($number, 2);
    }
    
    // ...
    
    <td><?php echo toCurrency($gasoilprice); ?></td>
    <td><?php echo toCurrency($dervprice); ?></td>
    <td><?php echo toCurrency($keroprice); ?></td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <div id=foo_<?php echo $id;?> class=hidden></div> I'm trying if
Trying to make a make generic select control that I can dynamically add elements
I'm trying to create an array to use for a curl_multi_exec, but I can't
I am new to PHP and trying to get the following code to work:
I am trying to get values out of an indexed array, but when I
I'm trying to transform a given line to an array, for example this line
I am trying to echo out an array using for each but it's not
I am trying to json encode an array,it does encode but i get lots
I am trying to pass multiple variables in a URL in PHP to GET
I'm trying to add results into a html dropdown. The php works if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.