ES6-Number
发布日期:2021-05-09 22:46:04 浏览次数:27 分类:精选文章

本文共 2730 字,大约阅读时间需要 9 分钟。

������ES6������������������������������

���������������������������������������������Input���������������������������������������������������������������Input���value������string������������������������������������������parseInt���������������������������������������������������������������������parseInt���������������������������������������������������������������������������������������������������������������������������parseFloat���������������������number���������������������������������������parseFloat������������������������������string������������������������������������������������������������������������������������������������������

���������������������������������������������������������������value���������number������������������������������������������

  • ������Number.parseFloat���string���������������������������������������������������������������������������
  • ������������������������������number������������������������������������������������������
  • ������������������������������������������������������������������������������������������������toFixed(2)������������������������������������������������������������������������number���������������������������������
  • ���������������������input������������������������������������������������������������������������������������������������������������������������������������

    ���������������������������������

    const reg = /^-?(0|[1-9][0-9])(.[0-9])?$/;

    ������������������������������

    • ���������������������������������������0������������������������������������������������������������
    • ���������������������������������������
    • ���������������������������������������������������������������

    ���������������������

    totalPrice = Number.parseFloat(num) * Number.parseFloat(price).toFixed(2);

    ���������value������������������������������������

    • typeof price => string
    • typeof parseFloat(price) => string
    • typeof Number.parseFloat(price) => number
    • typeof totalPrice => number
    • typeof totalPrice.toFixed(2) => string
    • typeof Number.parseFloat(totalPrice.toFixed(2)) => number

    ������������������������������������������������������������������������tprice���

    const tprice = Number(price) * Number(num).toFixed(2); totalPrice = Number(tprice.toFixed(2));

    ���������������������������������������������������������������������������

    ���������������������������������������

  • ���input������������������������������������������������������������
  • ���������������������������������������������������
  • ������������������������������������
  • ���������������������������������������������������������������������������������
  • ������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:前端-图片
    下一篇:JS-正则表达式

    发表评论

    最新留言

    路过按个爪印,很不错,赞一个!
    [***.219.124.196]2025年04月04日 11时06分21秒