Search code examples
vb.netdoublemoney-format

Money Format Number VB.NET


I'm trying to convert a mathematical result of money format example:

Dim num1 As Integer = 2000
Dim num2 As Integer = 500

msgbox(cDbl(num1 + num2))

It only returns 2500, which I need to return my 2,500.00 if anyone has any idea how I would be very helpful thanks.


Solution

  • Your MsgBox shows you the value, but it hasn't formatted it, as you haven't asked it to.

    If you went a little further and formatted the result as a string, you'll get the format you desire, e.g:

    Dim num1 As Double = 2000
    Dim num2 As Double = 500
    Dim sum As Double = num1 + num2
    
    MsgBox(sum.ToString("0.00")) ' Adjust format string to suit