Reputation: 34177
Can this equation be reworked to a correctly formatted string?
Dim Total = MyNumber / 100 * MyVAT
Produces error:
"Input string was not in a correct format"
Upvotes: 0
Views: 16443
Reputation: 2146
try with this statement
Dim Total = Val(MyNumber) / 100 * Val(MyVAT)
Upvotes: 2
Reputation: 460068
You should really set Option Strict
to on
. Then this would never compile since MyNumber
is a string(as you've commented).
You should first ensure that the input is numeric, for example with Decimal.TryParse
:
Dim Total As Decimal
Dim num As Decimal
If Decimal.TryParse(MyNumber, num) Then
Total = num / 100 * MyVAT
End If
Now you can use Decimal.ToString(format)
to convert it to a string with the desired format. For example(assuming you want two decimal places):
Dim output As String = Total.ToString("N2")
Standard Numeric Format Strings
Upvotes: 1
Reputation: 17614
use like below
Total.ToString("#")
More Detail:- http://msdn.microsoft.com/en-in/library/0c899ak8.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
Upvotes: 0