currency

ModuleNotFoundError: No module named 'forex_python'

ModuleNotFoundError: No module named 'forex_python' Question: As I was trying to practice building a Currency Converter python program, guided by one of the open resources, I installed forex-python and ensured it was installed: $ pip freeze certifi==2022.12.7 charset-normalizer==2.1.1 colorgram.py==1.2.0 forex-python==1.8 idna==3.4 Pillow==9.4.0 prettytable==3.5.0 prettyTables==1.1.5 requests==2.28.1 simplejson==3.18.1 urllib3==1.26.13 wcwidth==0.2.5 Then the code was copied/pasted without further …

Total answers: 1

How to sum price of human readable currency format?

How to sum price of human readable currency format? Question: I retrieve data from a website, the price column is 809.989K, 1.792M and I want to combine the numbers from the price column into a new column. My dataframe import pandas as pd data = { "price": ["809.989K", "1.792M"] } df = pd.DataFrame(data) df Desired …

Total answers: 1

How are currency units used with Python Pint units?

How are currency units used with Python Pint units? Question: I would like to do something like this: import pint ureg = pint.UnitRegistry() kg = ureg.kg USD = ureg.USD # not the way to do this weight = 2.3 * kg price = 1.49 * USD / kg cost = weight * price print(f"{cost:~.2f}") >>> …

Total answers: 1

How to solve MissingRate error in Django?

How to solve MissingRate error in Django? Question: I want to convert currencies in my Django app. I created a model Customer. In customer model, there are two fields for that credit_limit and currency_choice. I am using django-money for conversion. But I get an error: MissingRate at /customer Rate GBP -> USD does not exist …

Total answers: 2

Convert an amount to Indian Notation in Python

Convert an amount to Indian Notation in Python Question: Problem: I need to convert an amount to Indian currency format My code: I have the following Python implementation: import decimal def currencyInIndiaFormat(n): d = decimal.Decimal(str(n)) if d.as_tuple().exponent < -2: s = str(n) else: s = ‘{0:.2f}’.format(n) l = len(s) i = l-1; res = ” …

Total answers: 10

Convert currency to float (and parentheses indicate negative amounts)

Convert currency to float (and parentheses indicate negative amounts) Question: I have a df with currency: df = pd.DataFrame({‘Currency’:[‘$1.00′,’$2,000.00′,'(3,000.00)’]}) Currency 0 $1.00 1 $2,000.00 2 (3,000.00) I want to convert the ‘Currency’ dtype to float but I am having trouble with the parentheses string (which indicate a negative amount). This is my current code: df[[‘Currency’]] …

Total answers: 2

Converting Float to Dollars and Cents

Converting Float to Dollars and Cents Question: First of all, I have tried this post (among others): Currency formatting in Python. It has no affect on my variable. My best guess is that it is because I am using Python 3 and that was code for Python 2. (Unless I overlooked something, because I am …

Total answers: 6

What is the python for Java's BigDecimal?

What is the python for Java's BigDecimal? Question: In Java, when we program money it is recommended to use the class BigDecimal for money. Is there something similar in python? I would like something object-oriented that can have a currency and an exchange rate, has that been done? I store money as integers of cents …

Total answers: 1

Round an answer to 2 decimal places in Python

Round an answer to 2 decimal places in Python Question: The issue i am having is my rounding my results to 2 decimal places. My app gets the right results, however, i am having difficulty making the app round to the nearest decimal as you would with currency cost = input(“nEnter the 12 month cost …

Total answers: 5

Decimals to 2 places for money in Python 3

Decimals to 2 places for money in Python 3 Question: How do I get my decimals to stay at 2 places for representing money using the decimal module? I’ve setting the precision, and damn near everything else, and met with failure. Asked By: Musaab || Source Answers: One way to solve this is to store …

Total answers: 5