Js converts the decimal returned by the backend into a percentage. The operation of direct * 100 is incorrect?

< H2 > problem description < / H2 >

you need to use js to convert the decimal returned by the background into a percentage. I put this number * 100 directly in js, but the result is problematic.

:

clipboard.png

0.480.55


clipboard.png

ask me how to get these numbers to display properly.

Apr.29,2022

ask for help


try this item.paid_rate = (Math.min (item.paid_rate, 1) * 100) .tofixed (0)


clipboard.png
toFixed



jstoFixed0.54567


there is a problem of precision loss (or rounding error) in floating point calculation in computer programming language. The fundamental reason is that some digits are limited by binary and implementation digits.
the following is the binary representation of decimal decimal

   0.1 >> 0.0001 1001 1001 10011001
   0.2 >> 0.0011 0011 0011 00110011

the storage of each data type in a computer is a finite width, for example, JavaScript uses 64-bit to store digital types, so the excess is dropped. What is left out is the part where the precision is lost.

generally replace it with the corresponding integer to perform the operation.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f45a-4db1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f45a-4db1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?