Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

How do I shift the decimal place in Python?

The same way you do in math

a = 0.01;
a *= 10; // shifts decimal place right
a /= 10.; // shifts decimal place left

def move_point(number, shift, base=10):
    """
    >>> move_point(1,2)
    100
    >>> move_point(1,-2)
    0.01
    >>> move_point(1,2,2)
    4
    >>> move_point(1,-2,2)
    0.25
    """
    return number * base**shift

Tags:

Python

Decimal

Related

Check if a string is palindrome Error when running rails app - ExecJS::RuntimeError Stream response from CURL request without waiting for it to finish How do I query Jira to search for all issues that have been resolved within a length of time from when it was created? Where is Tomcat Console Output on Windows How to increment an alphanumeric string in PHP? how to convert a string to float and avoid using try/catch in java? How to insert multiple rows in a mysql database at once with prepared statements? Sanitize query string in PHP How can I convert a PNG file to PDF using java? Limit pagination page number Where is windows 4.5 bootstrapper package?

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy