Jump to content

[SOLVED] printf formatting


otuatail

Recommended Posts

Can anyone tell me whats wrong here.

 

I am trying to format 2 numbers 182.75 * 2 using

 

printf("%09.2f" , ($rs['Cost'] *  $rs['Q'])  )

 

instead of getting 000365.50

 

I get 000365.509 the last digit is the number of zeros on the end.

 

This is a shopping basket totals

 

Desmond.

 

Link to comment
https://forums.phpfreaks.com/topic/59978-solved-printf-formatting/
Share on other sites

<?php

printf("%09.2f" , 182.75 * 2  );          // --> 000365.50     

?>

 

If you don't want leading spaces or zeros, just use "%0.2f".

 

Alternatively

 

echo number_format( 182.75 * 2, 2);              // --> 365.50 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.