Reputation: 251
I'm calling a javascript function in a grid. Here is the code.
<div style="width: 100%; float: left; margin-bottom: 10px;">
<a href="#" onclick='<%# "ShowDetailPopup("+Eval("subscriberId").ToString()+","+Eval("Debt") +"," + Eval("Receivable") +","+
Eval("LegalAmount") + "," + Eval("fullName").ToString() +")" %>'>Detay</a>
</div>
Here is the js function.
function ShowDetailPopup(subscriberId, Debt, Receivable, LegalAmount, fullName) {
var popupWindow = pcDocument.GetWindowByName("showDocumentWindow");
pcDocument.ShowWindow(popupWindow);
pcDocument.SetWindowContentUrl(popupWindow, '/WEB/Pages/DebtAndReceiveDocument.aspx?ID=' + subscriberId + "&Debt=" + Debt +
"&Receivable=" + Receivable + "&LegalAmount=" + LegalAmount + "&fullName=" + fullName);
}
Debt
, Receivable
and LegalAmount
are all decimal fields.
Example values:
Debt = 4,65
Receivable = 13,00
LegalAmount = 0
When I call function, the page renders like this.
<a href="#" onclick='ShowDetailPopup(18069606,4,65,13,00,0,BILL GATES)'>Detay</a>
How can I correctly send the decimal values?
Upvotes: 0
Views: 1967
Reputation: 2111
You might also want to do Eval("Debt").ToString("0.00");
or better still, this will solve both:
Eval("Debt").ToString("F", CultureInfo.InvariantCulture))
so you always get two decimal places and a "." instead of a ","
I.e: 4 will be printed as 4.00 and something like 4,200,362.01 will be printed as 4200362.01
Upvotes: 1
Reputation: 304
It seems that you have a different Culture
set for client-side than on server-side. If you just want to replace the comma separator with a dot directly, try like this:
Eval("Debt")
will become
Eval("Debt").Replace(",", ".")
Upvotes: 2
Reputation: 4912
decimal Debt = Convert.ToDecimal("4.65");
Eval("Debt") return 4.65 and voila.
You can have 4,56 only if you declared your variable as string, so your problem is at variable type.
Eval(decimal) or Eval(double) returns number with floating point having "." not ","
Upvotes: 1