xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js number separator All In One

js number separator All In One

js 大数分隔符, 比较大的整数中按照每三位使用下划线分隔,更容易判断数字的值大小,更符合人类阅读

为了提高可读性,新的 JavaScript 语言功能允许下划线作为数字文字中的分隔符。

const bigNumber = 1000000000;
 

Big Number

const big_number = 1_000_000_000;
 

// A decimal integer literal with its digits grouped per thousand:
1_000_000_000_000

// A decimal literal with its digits grouped per thousand:
1_000_000.220_720

// A binary integer literal with its bits grouped per octet:
0b01010110_00111000

// A binary integer literal with its bits grouped per nibble:
0b0101_0110_0011_1000

// A hexadecimal integer literal with its digits grouped by byte:
0x40_76_38_6A_73

// A BigInt literal with its digits grouped per thousand:
4_642_473_943_484_686_707n

BigInt

const previouslyMaxSafeInteger = 9007199254740991n

const alsoHuge = BigInt(9007199254740991)
// ↪ 9007199254740991n

const hugeString = BigInt("9007199254740991")
// ↪ 9007199254740991n

const hugeHex = BigInt("0x1fffffffffffff")
// ↪ 9007199254740991n

const hugeOctal = BigInt("0o377777777777777777")
// ↪ 9007199254740991n

const hugeBin = BigInt("0b11111111111111111111111111111111111111111111111111111")
// ↪ 9007199254740991n


js convert number to commas number string (finance number)


function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}


const num = 34523453.345;

const  str = num.toLocaleString();

console.log(str); 
// "34,523,453.345"

https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript

Rust

Rust 基础数据类型

整数型(Integer)
整数型简称整型,按照比特位长度有无符号分为以下种类:

位长度 有符号 无符号
8-bit i8 u8
16-bit i16 u16
32-bit i32 u32
64-bit i64 u64
128-bit i128 u128

arch isize usize
isize 和 usize 两种整数类型是用来衡量数据大小的,它们的位长度取决于所运行的目标平台,如果是 32 位架构的处理器将使用 32 位位长度整型。

整数的表述方法有以下几种:

进制 例
十进制 98_222
十六进制 0xff
八进制 0o77
二进制 0b1111_0000
字节(只能表示 u8 型) b'A'

比较大的整数中按照进制(如:十进制每三位/ 二进制每四位)使用下划线分隔,更容易判断数字的值大小,更符合人类阅读

js convert number to binary / js convert number to hex

throttled=0x50000

n = 0x50000
327680
function dec2bin(dec) {
  return (dec >>> 0).toString(2);
}

dec2bin(327680)
'1010000000000000000'
m = 0x0
0
dec2bin(0)
'0'
n.toString(2)
'1010000000000000000'
n.toString(16)
'50000'

https://forums.raspberrypi.com/viewtopic.php?t=240215

https://raspberrypi.stackexchange.com/questions/119101/low-voltage-on-raspberry-pi

https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript

demos

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://v8.dev/features/numeric-separators
https://github.com/tc39/proposal-numeric-separator

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-10-31 15:51  xgqfrms  阅读(56)  评论(5编辑  收藏  举报