-3

I'm trying to round (d) with 2 decimals but i can't figure it out

if (c == "qc") or (c == "QC"):
    print("\nLe coût de l'objet que tu veut acheter est", a, "et ton budget est", b)
    blockPrint()
    d = input(a * g)
    enablePrint()
    print("le coût avec la tax est", d)
    if d > b:
        print("ton budget de", b, "est trop petit")
    else:
        print("tu as assé d'argent pour acheter ce que tu veux")
It_is_Chris
  • 13,504
  • 2
  • 23
  • 41

2 Answers2

0

To round you can use round(d, 2).

  • d is the var
  • 2 is the 2nd decimal place
RiveN
  • 2,595
  • 11
  • 13
  • 26
Jack
  • 23
  • 6
0

One approach is to use the round function, as I say in my comment. However, since you are doing this for a string print, it might be better to use a format string, like so:

if (c == "qc") or (c == "QC"):
    print(f"\nLe coût de l'objet que tu veut acheter est {a:.2f} et ton budget est {b:.2f}")
    blockPrint()
    d = int(a * g)
    enablePrint()
    print(f"le coût avec la tax est {d:.2f}")
    if d > b:
        print(f"ton budget de {b:.2f} est trop petit")
    else:
        print("tu as assé d'argent pour acheter ce que tu veux")
Ben Grossmann
  • 4,387
  • 1
  • 12
  • 16
  • i tried it but it but it gives me this print(f"le coût avec la tax est {d:.2f}") ValueError: Unknown format code 'f' for object of type 'str' – Furious Bomber Feb 15 '22 at 22:13
  • @FuriousBomber The problem is that `d` is a string instead of a float. What is the line `d = input(a * g)` supposed to do? What is `g`? – Ben Grossmann Feb 15 '22 at 22:16
  • a = input("Entre le prix de l'objet que tu veux acheter :"). A gets the price of the object and G is the tax 1.1495. B is the budget you have. – Furious Bomber Feb 15 '22 at 22:21
  • @FuriousBomber J'ai compris. So it should be `d = int(a*g)` instead of `d = input(a*g)`; see my latest edit – Ben Grossmann Feb 15 '22 at 22:58