Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 知乎专栏 | 视频教程 | About

22.8. Type

22.8.1. String

			
var a = "I want apple";
var b = "an";
var position = 6;
var output = [a.slice(0, position), b, a.slice(position)].join('');
console.log(output);

var n = "123456780";
var dot = ".";
var decimals = 4 * -1;
var output = [n.slice(0, decimals), dot, n.slice(decimals)].join('');
console.log(Number(output));
			
			

22.8.2. Number

			
var number = Number("1000000");
console.log(number);
			
			

22.8.3. BigNumber

http://mikemcl.github.io/bignumber.js/

			
const BigNumber = require('bignumber.js');

// 93774367102000000000 - 378000000000000 = 93773989102000010000

x = new BigNumber(93774367102000000000);
y = new BigNumber(378000000000000);
z = x.minus(y);	
z.toString();

n = 3.456
n = new BigNumber(x)
n.toFixed(5)
n.toFixed(10)