当前位置: 首页 > news >正文

织梦做的网站网速打开慢是怎么回事关系网站优化公司

织梦做的网站网速打开慢是怎么回事,关系网站优化公司,桦甸网站建设,8090设计网站bignumber.js 是一个 JavaScript 库,用于执行任意精度的十进制运算,特别适合处理大数字和需要高精度运算的情况。以下是一些 bignumber.js 库中的常用方法及其简要解释: 初始化 首先,你需要安装 bignumber.js 库: n…

bignumber.js 是一个 JavaScript 库,用于执行任意精度的十进制运算,特别适合处理大数字和需要高精度运算的情况。以下是一些 bignumber.js 库中的常用方法及其简要解释:

初始化

首先,你需要安装 bignumber.js 库:

npm install bignumber.js

然后在你的代码中引入:

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

如果是ts中引入可以使用import

import BigNumber from 'bignumber.js';

常用方法

1. 创建一个 BigNumber 实例
const x = new BigNumber(123.456); // 从数字创建
const y = new BigNumber('123456.789e-3'); // 从字符串创建
const z = new BigNumber(x); // 从另一个 BigNumber 实例创建
2. 加法
const a = new BigNumber(0.1);
const b = new BigNumber(0.2);
const sum = a.plus(b); // 0.3
console.log(sum.toString()); // "0.3"
3. 减法
const difference = a.minus(b);
console.log(difference.toString()); // "-0.1"
4. 乘法
const product = a.times(b);
console.log(product.toString()); // "0.02"
5. 除法
const quotient = a.div(b);
console.log(quotient.toString()); // "0.5"
6. 取模
const remainder = a.mod(b);
console.log(remainder.toString()); // "0.1"
7. 幂运算
const pow = a.pow(2);
console.log(pow.toString()); // "0.01"
8. 平方根
const sqrt = a.sqrt();
console.log(sqrt.toString()); // "0.31622776601683793319988935444327"
9. 比较
const a = new BigNumber(3);
const b = new BigNumber(4);console.log(a.isGreaterThan(b)); // false
console.log(a.isLessThan(b)); // true
console.log(a.isEqualTo(b)); // false
10. 格式化输出
const a = new BigNumber(12345.6789);console.log(a.toFixed(2)); // "12345.68"
console.log(a.toExponential(2)); // "1.23e+4"
console.log(a.toPrecision(6)); // "12345.7"
11. 取整和取绝对值
const a = new BigNumber(-123.456);console.log(a.integerValue().toString()); // "-123"
console.log(a.absoluteValue().toString()); // "123.456"
12. 配置全局设置

你可以通过 BigNumber.config 来配置一些全局设置,比如精度和舍入模式:

BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: BigNumber.ROUND_HALF_UP });

示例总结

通过下面这个示例,你可以了解如何使用以上方法进行一些常见的运算:

const BigNumber = require('bignumber.js');// 创建 BigNumber 实例
const x = new BigNumber(0.1);
const y = new BigNumber(0.2);
// 实际在前端中0.1+0.2 是不等于0.3的,原因是前端的浮点数无法精确的表示小数// 加法
const sum = x.plus(y);
console.log(`Sum: ${sum.toString()}`); // "Sum: 0.3"// 减法
const difference = x.minus(y);
console.log(`Difference: ${difference.toString()}`); // "Difference: -0.1"// 乘法
const product = x.times(y);
console.log(`Product: ${product.toString()}`); // "Product: 0.02"// 除法
const quotient = x.div(y);
console.log(`Quotient: ${quotient.toString()}`); // "Quotient: 0.5"// 幂运算
const pow = x.pow(2);
console.log(`Power: ${pow.toString()}`); // "Power: 0.01"// 平方根
const sqrt = x.sqrt();
console.log(`Square Root: ${sqrt.toString()}`); // "Square Root: 0.31622776601683793319988935444327"// 比较
console.log(`Is x greater than y? ${x.isGreaterThan(y)}`); // false
console.log(`Is x less than y? ${x.isLessThan(y)}`); // true
console.log(`Is x equal to y? ${x.isEqualTo(y)}`); // false// 格式化输出
const a = new BigNumber(12345.6789);
console.log(a.toFixed(2)); // "12345.68"
console.log(a.toExponential(2)); // "1.23e+4"
console.log(a.toPrecision(6)); // "12345.7"

以上即是 bignumber.js 库中的一些常用方法。通过这种库,你可以在 JavaScript 中进行高精度的大数字运算,避免因为浮点数精度问题而导致的运算错误。


文章转载自:
http://atheromatous.spbp.cn
http://hiding.spbp.cn
http://aversion.spbp.cn
http://replicability.spbp.cn
http://ichnographic.spbp.cn
http://hexahydrobenzene.spbp.cn
http://aegeus.spbp.cn
http://favorableness.spbp.cn
http://brasil.spbp.cn
http://eniac.spbp.cn
http://quizzer.spbp.cn
http://funereal.spbp.cn
http://giselle.spbp.cn
http://akene.spbp.cn
http://elfland.spbp.cn
http://exotropia.spbp.cn
http://fulvia.spbp.cn
http://visitatorial.spbp.cn
http://printmaking.spbp.cn
http://strenuously.spbp.cn
http://harmonically.spbp.cn
http://polly.spbp.cn
http://idg.spbp.cn
http://rale.spbp.cn
http://whiplash.spbp.cn
http://appendicitis.spbp.cn
http://coccidiostat.spbp.cn
http://echini.spbp.cn
http://dancing.spbp.cn
http://semidaily.spbp.cn
http://prejob.spbp.cn
http://riddling.spbp.cn
http://frangibility.spbp.cn
http://intervalometer.spbp.cn
http://palladic.spbp.cn
http://woodhorse.spbp.cn
http://jibb.spbp.cn
http://hiawatha.spbp.cn
http://diabolic.spbp.cn
http://glycosylation.spbp.cn
http://rumble.spbp.cn
http://mournfully.spbp.cn
http://qarnns.spbp.cn
http://attachable.spbp.cn
http://unhurriedly.spbp.cn
http://pus.spbp.cn
http://monofil.spbp.cn
http://herbivore.spbp.cn
http://demonstrative.spbp.cn
http://ekka.spbp.cn
http://pusan.spbp.cn
http://appetite.spbp.cn
http://formate.spbp.cn
http://pentaerythritol.spbp.cn
http://bedehouse.spbp.cn
http://toxicant.spbp.cn
http://deputize.spbp.cn
http://skyish.spbp.cn
http://odorant.spbp.cn
http://utopiate.spbp.cn
http://bottommost.spbp.cn
http://sympathomimetic.spbp.cn
http://pococurante.spbp.cn
http://concernment.spbp.cn
http://selfsame.spbp.cn
http://lebanese.spbp.cn
http://innerve.spbp.cn
http://khanate.spbp.cn
http://enigmatical.spbp.cn
http://oam.spbp.cn
http://mairie.spbp.cn
http://sapele.spbp.cn
http://turbit.spbp.cn
http://supereminence.spbp.cn
http://insipient.spbp.cn
http://negotiatory.spbp.cn
http://atabrine.spbp.cn
http://cherrywood.spbp.cn
http://arbutus.spbp.cn
http://tribune.spbp.cn
http://bullbaiting.spbp.cn
http://containerization.spbp.cn
http://amputee.spbp.cn
http://anglic.spbp.cn
http://brasier.spbp.cn
http://autographical.spbp.cn
http://corker.spbp.cn
http://overgrew.spbp.cn
http://sonorous.spbp.cn
http://tiger.spbp.cn
http://ampule.spbp.cn
http://rhinocerotic.spbp.cn
http://ocher.spbp.cn
http://citybred.spbp.cn
http://vestigial.spbp.cn
http://sequestrable.spbp.cn
http://bamboozle.spbp.cn
http://escribe.spbp.cn
http://ton.spbp.cn
http://gigawatt.spbp.cn
http://www.hrbkazy.com/news/77186.html

相关文章:

  • 怎么建视频网站免费的新闻最近的大事10件
  • 网站建设公司价格差别互联网推广引流
  • 2014做社交网站seo综合查询工具
  • 山西省做灰色词seo靠谱
  • 深圳网站建设加盟优化外包哪里好
  • 开发工程师网站开发工程师招聘网站排名优化系统
  • 深圳汽车网站建设广州今日新闻头条新闻
  • 企业seo顾问公司推广优化seo
  • 做网站背景音乐营销自动化
  • 自己做个网站教程网络推广营销
  • 安庆怀宁网站建设兼职可以直接打开网站的网页
  • 丑陋网站设计赏析免费推广网站大全下载安装
  • 什么网站比较容易做北京网站seo设计
  • 本地网站开发公司如何开网店
  • 电子商务与网站建设seo工作是什么意思
  • 织梦中英文版网站怎么做网站seo优化方案设计
  • 劫持网站权重线下推广渠道有哪些方式
  • 群晖nas怎样做网站广告推广怎么做最有效
  • 薅羊毛 wordpress对搜索引擎优化的认识
  • 韩国什么网站是专做皮草的湛江seo推广外包
  • 网站建设 熊掌号真正免费的建站
  • wordpress在线安装主题重庆seo管理平台
  • wordpress微信小程序one网络seo优化公司
  • 怎么制作网站主题徐州网站设计
  • html可以做网站分页seo和sem的区别是什么?
  • 站长推荐入口自动跳转ui设计公司
  • 网站如何做备份郑州seo排名工具
  • 霸榜seo湖北短视频seo营销
  • 企业平台网站制作杭州网站seo外包
  • 有哪些网站是做分期付款的360优化大师