This is a famous problem in computer world. It is originated from the IEEE 754 spec and binary system. Let’s see the problem at JavaScript:

var a = 0.2 + 0.4;
console.log(a);

In most browser, we may have the value 0.600…0001. It is very anonying when we want to show a value with decimal point. There are a lot of methods to deal with it. We focus on round and parseFloat:

  1. Math.round(a * 10) / 10

  2. parseFloat(a.toFixed(1))

I believe that you will say method 1 has high performance. But how faster it has?

Please see the result here: http://jsperf.com/round-vs-tofix-parsefloat

Centered Square Box in CSS

How to create a centered square box only with CSS? Continue reading

How to Add a Web as Application at Windows?

Published on August 11, 2019

Let's Meet at PyCon 2017 Taiwan

Published on May 09, 2017