I have a small tab on an app that allows user to lookup a price in a price table and it returns the price. how can i get the ‘$’ sign on the returned price?
public double? SearchMedicinePrice(Int64 pNDC)
{
double? retValue = null;
objConext = new FDBEntities();
Medicine objMedicine = objConext.Medicines.Where(med => med.PriceType == 9 && med.NDC == pNDC).OrderByDescending(item=>item.MedicineID).FirstOrDefault();
if (objMedicine != null)
{
retValue = objMedicine.Price;
}
return retValue;
}
When you call
ToString()on adouble(and many other types), you can pass in a format string to specify how the result should be formatted. Like this:Output =
$10.50You could also use String.Format like this:
{0:C}is a format string. TheCspecifies that the value should be formatted as currency.You can also pass in a
CultureInfoobject to configure things like the currency symbol. For example, the following code will output£10.50You might also consider using decimal instead of
doublefor storing currency data.