0

I have a number declaration

$barcode_scan = '220008100383005193';

and I want the output like this 0.519.

I already try this code

number_format(substr($barcode_scan, -6), 0, '', '.');

but the output is 5.193. Any help? Thanks

Avinash Dalvi
  • 8,551
  • 7
  • 27
  • 53
daliahdaud
  • 13
  • 1
  • Why are you trying to take off the '2200081003830', what's the criteria? – Mark Nov 22 '19 at 09:05
  • 3
    This looks amazingly like [this](https://stackoverflow.com/questions/58989475/convert-a-number-to-decimal-number-without-rounding) other question. – Nigel Ren Nov 22 '19 at 09:08
  • I don't understand your question, but is this what you want? https://3v4l.org/HLpqi – nice_dev Nov 22 '19 at 09:13
  • because the $barcode_scan is a barcode from a product. The last six of $barcode_scan actually is a weight of product. That's why I want to take off the other number – daliahdaud Nov 22 '19 at 09:24

2 Answers2

1

Something similar was here.

In your case code should be next:

$barcode_scan = '220008100383005193';
echo floor(number_format(substr($barcode_scan, -6), 0, '', '.')*100)/1000;

Outputs:

0.519
Aksen P
  • 4,564
  • 3
  • 14
  • 27
0

Try with following code

number_format(substr($barcode_scan, -6)/10000, 3)

OR

number_format(substr($barcode_scan, -6)/10000, 3, '.', ',')

That is conflict of decimal point symbol and thousand separator symbol