suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Konvertieren Sie eine Zeichenfolge in eine Zahl. Ein Beispiel ist a="2.322,222", b='1.211,21'. So führen Sie eine Subtraktion in Angular durch

Das Beispiel ist a="2,322,222",b='1,211,21', wie man eine Winkelsubtraktion durchführt

伊谢尔伦伊谢尔伦2829 Tage vor570

Antworte allen(2)Ich werde antworten

  • 怪我咯

    怪我咯2017-05-16 13:46:20

    function(a, b) {
        a = a.replace(',', '');
        b = b.replace(',', '');
        return (+a - +b).toFixed(2);
    }
    

    Antwort
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:46:20

    使用split(',')按找‘,’分成多个数组,根据长度判断,比如a就是 21000 b就是 11000,更多逗号,就是根据长度判断,长度为3就是下标为0的时候10001000 考虑 Math.pow(10,n * 3) 方法,装换成数字进行相减。可以试试

    Antwort
    0
  • StornierenAntwort