I am trying to make my Point of Sales program look more professional. I am storing the prices of products in a database as integers. Then, when I import these product prices into my program, the prices do not look very good.
For example, the price of product A is $2.00. This is what I store in my database in a currency column. Then, I import this into my program, and change a label to display the price:
Label1.Text = "$" & ProductPrice
Where ProductPrice is an integer.
However, instead of the price being displayed as "$2.00", it is displayed as "$2". I came up with this solution that works to sort of solve my problem:
If InStr(ProductPrice.ToString, ".") > 0 Then
Label1.Text = "$" & ProductPrice & "0"
Label1.Text = "$" & ProductPrice & ".00"
You might be thinking now that I don't have a problem, but there is a problem with the code above. It works fine if the ProductPrice is "2.5", as it changes it to "$2.50", or if the ProductPrice is "2", as that is changed to "$2.00", but if the price is "2.99", then it will change it to "$2.990".
Now finally, to my question. How can I count the number of digits after the decimal place, so that if there are 2 numbers after the decimal place, like "2.99", then it won't add the zero ($2.99), but if there is only one "2.5", then it will add a zero ($2.50).
Hopefully this makes sense!