Thanks very much for your help.
في الجمعة، 25 مارس 2022 في تمام الساعة 6:04:35 م UTC+2، كتب 
[email protected] رسالة نصها:

> Check out the description of toFixed on MDN: 
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
>
> It doesn't cover your specific example, but it does cover the differences 
> between, e.g., Number(2.35).toFixed(1) and Number(2.55).toFixed(1).
>
> The TL;DR here is that floating point numbers are represented in a 
> non-intuitive way internally to your computer (IEEE 754), and the toFixed 
> function doesn't take the time to perform the rounding in the way you 
> expect. You can generally achieve the rounding you want my multiplying your 
> number by a factor (in your case, 100), calling Math.round() on the result, 
> dividing it again by the same factor used previously, and then formatting 
> that with toFixed().
>
> On Thursday, March 24, 2022 at 3:35:43 PM UTC-7 [email protected] wrote:
>
>> By looking into this example:
>> var x = 1.245;
>> var xFixed = x.toFixed(2);
>> xFixed value should be 1.25
>> but it is printing 1.24
>>
>>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/015b0fe6-95e3-4926-bbfa-5896d968e7f1n%40googlegroups.com.

Reply via email to