错误脚本给出的数字为e + 22 [关闭]

I have a PHP code that give number value to abox when i click at the number if he was high number like 10000000000000000000000 it giving me in the box (1e+22) the code is:

echo "\t\t\t\t</div>
\t\t\t</td>
\t\t\t<td class=\"val\"><input type=\"text\" class=\"text\" id=\"_tf";
    echo number_format($tid,0,'','');
    echo "\" name=\"tf[";
    echo number_format($tid,0,'','');
    echo "]\" value=\"0\" maxlength=\"100\"></td>
\t\t\t<td class=\"max\"><a href=\"#\" onclick=\"_('_tf";
    echo number_format($tid,0,'','');
    echo "').value=";
    echo number_format($maxNumber,0,'','');
    echo "; return false;\">(";
    echo number_format($maxNumber,0,'','');
    echo ")</a><br>";
    echo number_format($maxNumber,0,'','');
    echo "</td>
\t\t</tr>
\t\t";

like this enter image description here

I want to give me the number without e+

I found a js function for your scientific writing number,

// will return something as 1 12 123 1k 12k 0.1m [...]
function abbreviateNumber(value) {
    var formatedValue = value;
    if (value >= 1000) {
        var suffixes = ["", "k", "m", "b","t"];
        var suffixNum = Math.floor( (""+value).length/3 );
        var shortValue = '';
        for (var precision = 2; precision >= 1; precision--) {
            shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
            var dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
        if (dotLessShortValue.length <= 2) { break; }
    }
    if (shortValue % 1 != 0)  shortNum = shortValue.toFixed(1);
    formatedValue = shortValue+suffixes[suffixNum];
}
return formatedValue;

}

IQV is right, becareful to your tag, we are in js (php), but it doesn't matter.

Two issues:

  1. The number is being formatted in scientific notation. I think your PHP is outputting it as a string in normal notation thanks to your use of number_format(x, 0, '.', '') (it does on my PHP implemntation), so JavaScript code you haven't shown is reading that string as a number and then turning it back into a string, which formats it in scientific notation.

    To avoid that, pass the number to JavaScript as a string, and use the string. (You can also convert it to a number if you like to use it in a calculation, but beware #2 below.)

  2. The number is well above the point at which even whole numbers are subject to precision issues in the number system JavaScript uses (IEEE-754 double-precision binary floating point numbers). For instance, 9007199254740991 (aka Number.MAX_SAFE_INTEGER) and 9007199254740992 can be correctly represented, but they're the last ones where you can keep counting upward by just 1; 9007199254740993 cannot be correctly represented. (If you add 1 to 9007199254740992, you still get 9007199254740992; to move past it, you have to add 2. The further upward you go, the bigger those gaps get.) Your specific example is okay because it's one of the ones that can be correctly represented, but any calculation you do with it will be suspect because (for instance) 10000000000000000000000 - 1 is still 10000000000000000000000. Heck, even 10000000000000000000000 - 457 is still 10000000000000000000000, that's how far into the realm of imprecision it is.

You haven't quoted the code where the problem is, but for instance, this page correctly shows the number (and also shows it in scientific notation):

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Show The Number</title>
<style>
body {
    font-family: sans-serif;
}
</style>
</head>
<body>
<?php
$theNumber = 10000000000000000000000;
echo '<input type="text" value="' . number_format($theNumber, 0, '.', '') . '" id="foo">';
?>
<script>
var p = document.createElement("p");
// Get the *string* from the input
var numstr = document.getElementById("foo").value;
// Convert it to a number
var num = +numstr;
// Show both
p.innerHTML = "The number is " + numstr + " (" + num + ")";
document.body.appendChild(p);
</script>
</body>
</html>