我有一個表單接受來自多個字段的貨幣,並根據我輸入的內容計算其他貨幣。對於這個大部分下面的代碼工作(例如是發票金額字段)xpages貨幣不完整輸入失敗
<xp:inputText value="#{FInvoiceDoc.InvoiceAmount}" id="InvoiceAmount">
<xp:this.converter>
<xp:convertNumber type="currency"></xp:convertNumber></xp:this.converter>
<xp:eventHandler event="onchange" submit="false" id="eventHandler5">
<xp:this.script><![CDATA[var rate = XSP.getElementById("#{id:ExchangeRate}").value;
var stAmount = XSP.getElementById("#{id:InvoiceAmount}").value;
var stTvat = XSP.getElementById("#{id:TVAT}").value;
var stTst = XSP.getElementById("#{id:TST}").value;
var stToop = XSP.getElementById("#{id:Toop}").value;
var tmp;
// get the dojo currency code
dojo.require("dojo.currency");
// get the numeric values using parse
amount = dojo.currency.parse(stAmount,{currency:"USD"});
total = rate * amount;
XSP.getElementById("#{id:EstUSAmount}").innerHTML = dojo.currency.format(total,{currency:"USD"});
XSP.getElementById("#{id:InvoiceAmount}").value = dojo.currency.format(amount,{currency:"USD"});
if (amount != 0) {
tvat = dojo.currency.parse(stTvat,{currency:"USD"});
tst = dojo.currency.parse(stTst,{currency:"USD"});
toop = dojo.currency.parse(stToop,{currency:"USD"});
tmp = (tvat/(amount-tvat-tst-toop)) * 100;
XSP.getElementById("#{id:VP}").innerHTML = tmp.toFixed(2);
tmp = (tst/(amount-tvat-tst-toop)) * 100;
XSP.getElementById("#{id:STP}").innerHTML = tmp.toFixed(2);
tmp = (toop/(amount-tvat-tst-toop)) * 100;
XSP.getElementById("#{id:OoPP}").innerHTML = tmp.toFixed(2);
}
]]></xp:this.script>
</xp:eventHandler>
</xp:inputText>
就像我說的,這個作品在大多數情況下,但如果我只輸入像部分號碼
200.2
代替
200.20
那麼它失敗。大多數數據輸入人員不希望鍵入最後的「0」,因此它是合法的。
順便說一句,如果我輸入它只有200沒有美分,它沒關係。
這就好像聲明;
amount = dojo.currency.parse(stAmount,{currency:「USD」});
需要2位數的便士數量或沒有便士,但不喜歡只有領先的美分數字。
任何方法?
閱讀此:http://www-10.lotus.com/ldd/ddwiki.nsf/dx/converters-on-an-xpage.htm,並測試不同的轉換器。 –