Search code examples
pythonpython-3.xtkintertkinter-entrytkinter-text

So I'm Facing A Issue Here, During Calculating The Data Its Ignoring Decimal And Just Calculating The Integer, 10*11.50 Should Be 115


enter image description here

1st Image Is The Code For Calculation And The qty,rate,disc are all intvar text variables

enter image description here 2nd Image Is The Error What I Am Getting The Calculation Is Wrong The Code Is Ignoring the decimal And Just Calculating The 11 Where Am I Wrong Please Guide Me Hope You Are Getting My Problem

Let Me Be Clear I Am A NewBie In Python And Tkinter


Solution

  • It looks like what's happening here is 11.5 is casting to an integer, and as a result, is rounding down to 11. At the risk of over-explaining, there are several different data types for numbers. Integers are always whole numbers, positive or negative, but can't have a decimal part. If you try to create an integer with a decimal part, it will create the integer, but ignore the decimal part and just keep the whole number part, effectively rounding down. The data type "double" can hold decimals, so try using DoubleVar() instead of IntVar() for anything you might want to have a decimal part.