currency

Convert currency to float (and parentheses indicate negative amounts)

a 夏天 提交于 2019-11-29 02:16:42
问题 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']] = df[['Currency']].replace('[\$,]','',regex=True).astype(float) which produces an error: ValueError: could not convert string to float: (3000.00) What I want as dtype float is:

Storing currency values in SQLite3

a 夏天 提交于 2019-11-29 01:41:12
I'm dealing with lots of different currencies in my application, and I want to know what the "best" way is to store them in an SQLite3 database. I'm leaning towards a fixed-point representation (i.e. store them as integers, where $3.59 gets stored as 359, ¥400 stored as 40000). Is this a good idea? What if my input data later changes and requires more precision? Given that SQLite 3 will use up to 8 bytes to store INTEGER types, unless you are going to have numbers greater than 10^16, you should be just fine. To put this in perspective, the world gross domestic product expressed in thousandths

How to avoid rounding problems when comparing currency values in Delphi?

此生再无相见时 提交于 2019-11-29 00:42:55
AFAIK, Currency type in Delphi Win32 depends on the processor floating point precision. Because of this I'm having rounding problems when comparing two Currency values, returning different results depending on the machine. For now I'm using the SameValue function passing a Epsilon parameter = 0.009, because I only need 2 decimal digits precision. Is there any better way to avoid this problem? The Currency type in Delphi is a 64-bit integer scaled by 1/10,000; in other words, its smallest increment is equivalent to 0.0001. It is not susceptible to precision issues in the same way that floating

Struggling with currency in Cocoa

不羁岁月 提交于 2019-11-29 00:14:36
I'm trying to do something I'd think would be fairly simple: Let a user input a dollar amount, store that amount in an NSNumber (NSDecimalNumber?), then display that amount formatted as currency again at some later time. My trouble is not so much with the setNumberStyle:NSNumberFormatterCurrencyStyle and displaying floats as currency. The trouble is more with how said numberFormatter works with this UITextField. I can find few examples. This thread from November and this one give me some ideas but leaves me with more questions. I am using the UIKeyboardTypeNumberPad keyboard and understand

Do minor currency units have a ISO standard?

旧时模样 提交于 2019-11-29 00:10:56
问题 ISO 4217 defines 3-letter currency symbols: EUR USD LKR GBP Do currencies' minor units (cent, pence) have a ISO or similar standard, too, that defines codes for those sub-units like ct p ? 回答1: The standard also defines the relationship between the major currency unit and any minor currency unit. Often, the minor currency unit has a value that is 1/100 of the major unit, but 1/1000 is also common. Some currencies do not have any minor currency unit at all. In others, the major currency unit

Locale Currency Symbol

余生颓废 提交于 2019-11-28 23:39:16
I having some problems getting the default currency symbol of the system. I am getting the currency symbol this way: Currency currency = Currency.getInstance(Locale.getDefault()); Log.v("TAG",currency.getSymbol()); When the system language is in English (United States) the right symbol shows up ( $ ). But when i choose the language Portuguese (Portugal) it returns this symbol ¤ . What can be causing this? This seems to be a known issue ( http://code.google.com/p/android/issues/detail?id=38622 . I came to a possible solution this way: Since the problem is in the Symbol and not the Currency code

Decimals to 2 places for money in Python 3

你离开我真会死。 提交于 2019-11-28 23:23:26
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. patrys When working with money you usually want to limit precision as late as possible so things like multiplication don't aggregate rounding errors. In python 2 and 3 you can .quantize() a Decimal to any precision you want: unit_price = decimal.Decimal('8.0107') quantity = decimal.Decimal('0.056') price = unit_price * quantity cents = decimal.Decimal('.01') money = price.quantize(cents, decimal.ROUND_HALF_UP) The

If dealing with money in a float is bad, then why does money_format() do it?

不羁的心 提交于 2019-11-28 23:09:49
I've been waffling on how to deal with currency display and math in PHP, and for a long time have been storing it in MySQL using the DECIMAL type, and using money_format() to format it for display on the web page. However, today I looked at the actual prototype: string money_format ( string $format , float $number ) I'm a little confused now. All I've been told is, avoid floats for money! But here it is, the fundamental formatting function (say that five times fast), casting the input to a float. number_format() does the same. So my questions are: Unless I'm dealing with fractional cents or

How to get Delphi Currency Type to Round like Excel all the time?

断了今生、忘了曾经 提交于 2019-11-28 21:43:39
I'm trying to get Delphi to Round like Excel but I can't. Here is the code: procedure TForm1.Button1Click(Sender: TObject); var s : string; c : currency; begin c := 54321.245; s := ''; s := s + Format('Variable: %m',[c]); s := s + chr(13); s := s + Format(' Literal: %m',[54321.245]); ShowMessage(s); end; I'm using a currency variable that is set to 54321.245 and when I format this variable it rounds using Bankers Rounding. However, when I format the same value as a literal it rounds the way that Excel rounds. I was expecting this to round to $54,321.25 whether it's formating a currency

How to parse a currency Amount (US or EU) to float value in Java

大城市里の小女人 提交于 2019-11-28 21:32:05
In Europe decimals are separated with ' , ' and we use optional ' . ' to separate thousands. I allow currency values with: US-style 123,456.78 notation European-style 123.456,78 notation I use the next regular expression (from RegexBuddy library) to validate the input. I allow optional two-digits fractions and optional thousands separators. ^[+-]?[0-9]{1,3}(?:[0-9]*(?:[.,][0-9]{0,2})?|(?:,[0-9]{3})*(?:\.[0-9]{0,2})?|(?:\.[0-9]{3})*(?:,[0-9]{0,2})?)$ I would like to parse a currency string to a float. For example 123,456.78 should be stored as 123456.78 123.456,78 should be stored as 123456.78