Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | Decimal sqrt() method
Next article icon

Python | Decimal as_integer_ratio() method

Last Updated : 05 Sep, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
Decimal#as_integer_ratio() : as_integer_ratio() is a Decimal class method which returns the exponent after shifting out the coefficient’s rightmost digits until only the lead digit remains : as a pair (n, d)
Syntax: Decimal.as_integer_ratio() Parameter: Decimal values Return: the exponent after shifting out the coefficient’s rightmost digits until only the lead digit remains : as a pair (n, d)
Code #1 : Example for as_integer_ratio() method Python3
# Python Program explaining  # as_integer_ratio() method  # loading decimal library from decimal import *   # Initializing a decimal value a = Decimal(-1)  b = Decimal('0.142857')  # printing Decimal values print ("Decimal value a : ", a) print ("Decimal value b : ", b)   # Using Decimal.as_integer_ratio() method print ("\n\nDecimal a with as_integer_ratio() method : ", a.as_integer_ratio())  print ("Decimal b with as_integer_ratio() method : ", b.as_integer_ratio()) 
Output :
  Decimal value a :  -1  Decimal value b :  0.142857      Decimal a with as_integer_ratio() method :  (-1, 1)  Decimal b with as_integer_ratio() method :  (142857, 1000000)    
Code #2 : Example for as_integer_ratio() method Python3
# Python Program explaining  # as_integer_ratio() method  # loading decimal library from decimal import *   # Initializing a decimal value a = Decimal('-3.14')  b = Decimal('321e + 5')  # printing Decimal values print ("Decimal value a : ", a) print ("Decimal value b : ", b)   # Using Decimal.as_integer_ratio() method print ("\n\nDecimal a with as_integer_ratio() method : ", a.as_integer_ratio())  print ("Decimal b with as_integer_ratio() method : ", b.as_integer_ratio()) 
Output :
  Decimal value a :  -3.14  Decimal value b :  3.21E+7      Decimal a with as_integer_ratio() method :  (-157, 50)  Decimal b with as_integer_ratio() method :  (32100000, 1)  

Next Article
Python | Decimal sqrt() method

N

noobestars101
Improve
Article Tags :
  • Python
Practice Tags :
  • python

Similar Reads

  • Python | Decimal is_zero() method
    Decimal#is_zero() : is_zero() is a Decimal class method which checks whether the Decimal value is zero value. Syntax: Decimal.is_zero() Parameter: Decimal values Return: true - if the Decimal value is zero value; otherwise false Code #1 : Example for is_zero() method # Python Program explaining # is
    2 min read
  • Python | Decimal to_eng_string() method
    Decimal#to_eng_string() : to_eng_string() is a Decimal class method which converts to a string, using engineering notation if an exponent is needed. Syntax: Decimal.to_eng_string() Parameter: Decimal values Return: converts to a string Code #1 : Example for to_eng_string() method # Python Program ex
    2 min read
  • Python | Decimal as_tuple() method
    Decimal#as_tuple() : as_tuple() is a Decimal class method which returns named tuple representation of the Decimal value. Syntax: Decimal.as_tuple() Parameter: Decimal values Return: tuple with values - sign - digits - exponent Code #1 : Example for as_tuple() method # Python Program explaining # as_
    2 min read
  • Python | Decimal sqrt() method
    Decimal#sqrt() : sqrt() is a Decimal class method which returns the Square root of a non-negative number to context precision. Syntax: Decimal.sqrt() Parameter: Decimal values Return: the Square root of a non-negative number to context precision. Code #1 : Example for sqrt() method # Python Program
    2 min read
  • Python | Decimal is_finite() method
    Decimal#is_finite() : is_finite() is a Decimal class method which checks whether the Decimal value is finite value. Syntax: Decimal.is_finite() Parameter: Decimal values Return: true - if the Decimal value is finite value; otherwise false Code #1 : Example for is_finite() method # Python Program exp
    2 min read
  • Python | Decimal is_qnan() method
    Decimal#is_qnan() : is_qnan() is a Decimal class method which checks whether the Decimal value is quite NaN value. Syntax: Decimal.is_qnan() Parameter: Decimal values Return: true - if the Decimal value is quite NaN value; otherwise false Code #1 : Example for is_qnan() method # Python Program expla
    2 min read
  • Python | Decimal is_snan() method
    Decimal#is_snan() : is_snan() is a Decimal class method which checks whether the Decimal value is a signaling NaN Syntax: Decimal.is_snan() Parameter: Decimal values Return: true - if the Decimal value is a signaling NaN; otherwise false Code #1 : Example for is_snan() method # Python Program explai
    2 min read
  • Python | Decimal quantize() method
    decimal module helps you work with numbers that need high precision, like money or scientific calculations. quantize() method is used to round or format a decimal number to a specific number of decimal places while following a chosen rounding rule. For example, let's consider "n = 3.1459", when we a
    3 min read
  • Python | Decimal ln() method
    Decimal#ln() : ln() is a Decimal class method which returns the natural (base e) logarithm of the Decimal value. Syntax: Decimal.ln() Parameter: Decimal values Return: the natural (base e) logarithm of the Decimal value. Code #1 : Example for ln() method # Python Program explaining # ln() method # l
    2 min read
  • Python string isdecimal() Method
    In Python, the isdecimal() method is a quick and easy way to check if a string contains only decimal digits. It works by returning True when the string consists of digits from 0 to 9 and False otherwise. This method is especially useful when we want to ensure that user inputs or string data are stri
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences