Posted: 7/5/2011
I am working on a Point of sale module for a web application. I need help ensuring my data stays in a money format ie 0.00
Here's my code:
Double res = Double.Parse(PriceTxtBox.Text); res = res * Double.Parse(QtyTxtBox.Text); ItemTotalTxtBox.Text = res.ToString(); if (ItemTotalTxtBox != null) { Double rs = Double.Parse(ItemTotalTxtBox.Text); rs = (rs * (.075)) + Double.Parse(ItemTotalTxtBox.Text); Double ts = (rs *(.075)); TotalTxtBox.Text = rs.ToString(); TaxTxtBox.Text = ts.ToString(); }
I can handle constraing the input on the client side.
When PriceTxtBox is 2 and QtyTxtBox is 3 I need the result to be 6.00 not 6 like I am getting now.
When ItemTotalTxtBox is 4.67 I need TotalTxtBox to be 0.35 not 0.35025 like I am getting now.
Thanks in advance.
Posted: 7/22/2011
Hi mike,
Try this code it may help u
first include package : using System.Globalization;
then put the code................
public void show() { Double res = Double.Parse(PriceTxtBox.Text); res = res * Double.Parse(QtyTxtBox.Text); ItemTotalTxtBox.Text = formatDblToMoney(res); if (ItemTotalTxtBox != null) { Double rs = Double.Parse(ItemTotalTxtBox.Text); rs = (rs * (.075)) + Double.Parse(ItemTotalTxtBox.Text); Double ts = (rs * (.075)); TotalTxtBox.Text = formatDblToMoney(rs); TaxTxtBox.Text = formatDblToMoney(ts); } } public static string formatDblToMoney(Double d) { return String.Format(CultureInfo.CreateSpecificCulture("en-us"), "{0:N}", d); }