CurrencyConvert工作不完美

时间:2015-05-05 14:27:38

标签: javascript jquery html wkhtmltopdf

function numberToCurrency(amount) {

            var wholeDigits;
            var thousandsSeparator = "."
            var centSeparator = ","
            var currencyNum = "";

            if(amount.indexOf(".") != -1) {
                var hasCents = true;
            } else {
                var hasCents = false;
            }

            if (hasCents == true) {
                var num = amount.split(".");
                var wholeDigits = num[0].split("");
                var centAmount = num[1];
                var centDigits = num[1].split("");

                if (centDigits.length == 0) {
                    centDigits += "0";
                }
                if ((centDigits.length > 0) && (centDigits.length < 2)) {
                    centDigits += "0";
                }

            } else {
                centDigits = "";
                centSeparator = "";
                wholeDigits = amount.split("");
            }

            var countDigits = wholeDigits.length;

            var revDigits = wholeDigits.reverse();

            for(var i=0; i<countDigits; i++) {
                    if ((i%3 == 0) && (i !=0)) {
                        currencyNum += thousandsSeparator+revDigits[i];
                    } else {
                        currencyNum += wholeDigits[i];
                    }
            };

            var revCurrency = currencyNum.split("").reverse().join("");

            var finalCurrency = revCurrency+centSeparator+centAmount+"  €";

            return finalCurrency;
        }

我对这个转换有问题..

我如何成为价值观?

我成为了SQL的值..例如{{AMOUNT1}}在SQL表中,行“amount1”的值是:1839936,59

select AMOUNT1,* from INVOICE where INVOICENR = '123456'

然后我用这段代码在HTML中使用DOM:

<input id="AMOUNT1" type="text" title="1.839.936,59" initval="1839936,59" value="1839936,59" name="BETRAGNETTO" style="text-align:right;width:calc(100% - 18px) !important;" decimalplaces="2" numval="1839936.59"> 

我用于wkhtmltopdf模板的所有占位符.. 在.tmpl我这样写:

<td class="tr1 td2"><p class="p2 ft4"><script type="text/javascript">document.write(numberToCurrency('{{AMOUNT1}}'))</script></P></TD>

OUTPUT(在.pdf中) - 斜体字体= SQ L

  1. {{AMOUNT1}}:1.839.936,59€(在SQL中:1839636,59)

  2. {{AMOUNT2}}:55.198,1€(在SQL:55198,10中)&lt; ---小数位?

  3. {{AMOUNT3}}:0,0€(在SQL中:0,00)&lt; ---同样在这里

  4. {{AMOUNT4}}:15.733,979999999996€(在SQL:15733,97中)&lt; ---这是什么?

  5. 所有金额都不同,但在sql中都是一样的,比如xxxxx,xx。

    脚本有什么问题?

0 个答案:

没有答案