4

I have a number stored in scientific notation

2.01421700079E+14

I've tried using float, string, int and I can't get

0201421700079085 from 2.01421700079E+14

1. echo (float)$awb;
2. echo number_format($awb, 0, '', '');
3. echo (int)$awb;
4. echo (string)$awb;
  1. 2.01421700079E+14 = float
  2. 201421700079085 = number
  3. 201421700079085 = int
  4. 2.01421700079E+14 = string
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ikhsan Mahendri
  • 143
  • 2
  • 9

2 Answers2

7

printf and friends will do this:

<?php
$awb = 2.01421700079E+14;
$str = sprintf("%d", $awb);
var_dump($str);

Output:

string(15) "201421700079000"

There obviously isn't enough information in your original number to get any more precision than that.

miken32
  • 42,008
  • 16
  • 111
  • 154
  • may be different if result 0201421700079085, do you have new solution for me ? – Ikhsan Mahendri Apr 20 '17 at 04:51
  • You can't just invent numbers. You have a certain amount of precision in your input, you don't get any more precision than that. – miken32 Apr 20 '17 at 04:52
  • is for a import from excel to mysql but if i want to upload in mysql show this number 2.01421700079E+14, but in my excel is number 0201421700079085, do you have any solution for me ? – Ikhsan Mahendri Apr 20 '17 at 04:55
2

Try this:

number_format(1.2378147769392E+14,0,'','')
miken32
  • 42,008
  • 16
  • 111
  • 154
Umer iqbal
  • 196
  • 1
  • 2
  • 15
  • i try your code and result is 201421700079085 but i want result is 0201421700079085 with zero in front because the number string is 0201421700079085 – Ikhsan Mahendri Apr 20 '17 at 04:53
  • http://php.net/manual/en/refs.math.php try these libraries for better precision. default php libraries only provide limited functionalities in such case – Umer iqbal Apr 20 '17 at 05:19