I need to be able to work with decimals. Right now I am trying to subract 2 decimals and it is not working

I input 10.89 in price and 11 in change the result should be 0.11, but I get 0.19999999

Why?

price As Double

Dim change As Double

Double.TryParse(Me.TPrice.Text, Price)

Double.TryParse(Me.TChange.Text, change)

Dim variable1 As double

variable1 = change - price



Me.LDollars.Text = Convert.ToString(variable1)
Member Avatar for iamthwee

Maybe you are not converting the string to a double properly or you need to initialise variable1 to zero (at a guess).

Dim variable1 As Double
variable1 = 0

nope that did not work

Maybe you are not converting the string to a double properly or you need to initialise variable1 to zero (at a guess).

Dim variable1 As Double
variable1 = 0
Dim a1 As Decimal = 11
Dim a2 As Decimal = 10.89
TextBox1.Text = (a1 - a2).ToString

Declare the variable as decimal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.