Skip to content
Programs · Program 5-6

Q.Program 5-6: Program of explicit type conversion from float to int.

CBSENCERTSubjective· 2mImportance★★★★★est
24% · 12/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

int() performs explicit float → int conversion by truncating the decimal part — 47.95 becomes 47, never 48.

The idea (Explicit Type Conversion). Going from float to int is a "narrowing" conversion: the fractional part cannot be represented in an integer, so it is lost. Because data is lost, Python never does this implicitly — the programmer must ask for it explicitly with int(). Knowing exactly how the fraction is removed (truncation toward zero, not rounding) is the whole point of this program.

Program

# prog5-6.py
# Program of explicit type conversion from float to int
price = 47.95
priceInt = int(price)      # explicit float -> int
print(price)
print(priceInt)
print(type(priceInt))
print(int(-3.9))           # negative values truncate toward zero

Expected output

47.95
47
<class 'int'>
-3

Key lines

  • priceInt = int(price) — the cast simply drops everything after the decimal point: 47.95 → 47. The original price still holds 47.95. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.