CODE
BÀI VIẾT
<input id="nhaptien" value="" /> <div id="ratien"></div> <script> const node = document.getElementById("nhaptien"); node.addEventListener("keyup", function(event) { var n = document.getElementById("nhaptien").value; const formatCash = n => { if (n < 1e3) return n; if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(2) + " ngìn"; if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(2) + " triệu"; if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(2) + " tỷ"; if (n >= 1e12) return +(n / 1e12).toFixed(1) + " ức"; }; document.getElementById("ratien").innerHTML = '<b style="font-size:25px;color:#ff4444;margin:10px 0px;display:block">' + formatCash(n) + '</b>'; }); </script>
Nhập vào input hiển thị số dạng rút ngắn theo đơn vị
Javascript
ihoan
đã viết 8 tháng trước
Code này sẽ hiển thị ra số được rút ngăn theo đơn vị.
Ví dụ:
– 1000 = 1 ngìn
– 1000000 = 1 triệu
276
Bài viết cùng chủ đề
Cách để tạo một Modal, Popup bằng HTML, CSS, JS cơ bản
Bộ lọc select tỉnh thành, quận huyện sử dựng API provinces.open-api.vn
Bộ lọc select chọn Tỉnh Thành, Quận huyện, Xã phường, sử dụng data-id
Tạo hộp thời tiết bằng API openweathermap code Javascript
Code lịch hiển thị thời gian ngày tháng hiện tại bằng Javascript