Visual basic programming?
boss.checker asked:
Using 2005 vb -I want to declare variables as numbers, but I only want to show the number to two decimal places (£5.23 for example). How would I go about doing this?
any help would be greatly appreciated
Related posts:
- Visual Basic Programming Help? michbox asked: okay i created a simple income calculator but...
- Trouble Writing a basic program with Visual Basic 2005 Express? dconverse2 asked: A motorist wants to determine her gas mileage....
- Really Challenging Visual Basic Question Problem? ABC asked: I have a little problem. I need to...
- computer programming Visual Basic tutorial? John P asked: Can anyone show me how to work...
- Can you give me the code for a cool program for Visual basic 2008? spongebob asked: Ok i got visual basic 2008 express edition...
Filed Under Programming & Design |
Tagged With Decimal Places, Vb, Visual Programming
Comments
2 Responses to “Visual basic programming?”
Try this:
Dim int As Single = 1111.11
Dim strlnt As String
strlnt int.ToString(’£###,###.00′)
You declare the number as a Double, and when showing it, you use FormatCurrency, FormatNumber, or the simpler Format function.
FormatCurreny inserts the monetary symbol based on your computer settings, but acts the same as FormatNumber; FormatNumber allows you directly state the number of digits after the decimal; Format requires manually setting the, well… format:
amount = Format ( nrVar, “$#0,00″ )
amount = FormatCurrency ( nrVar, 2, true )
amount = “$” & FormatNumber ( nrVar, 2, true )