currency

String.Format(“{0:C2}”, -1234) (Currency format) treats negative numbers as positive

心不动则不痛 提交于 2019-11-30 06:36:09
I am using String.Format("{0:C2}", -1234) to format numbers. It always formats the amount to a positive number, while I want it to become $ - 1234 Am I right in saying it's putting it in brackets, i.e. it's formatting it as ($1,234.00) ? If so, I believe that's the intended behaviour for the US. However, you can create your own NumberFormatInfo which doesn't behave this way. Take an existing NumberFormatInfo which is "mostly right", call Clone() to make a mutable copy, and then set the CurrencyNegativePattern appropriately (I think you want value 2). For example: using System; using System

How can I correctly format currency using jquery?

夙愿已清 提交于 2019-11-30 06:18:48
问题 I do not need a mask, but I need something that will format currency(in all browsers) and not allow for any letters or special char's to be typed. Thanks for the help Example: Valid: $50.00 $1,000.53 Not Valid: $w45.00 $34.3r6 回答1: JQUERY FORMATCURRENCY PLUGIN http://code.google.com/p/jquery-formatcurrency/ 回答2: Another option (If you are using ASP.Net razor view) is, On your view you can do <div>@String.Format("{0:C}", Model.total)</div> This would format it correctly. note (item.total is

How to define money amounts in an API

别等时光非礼了梦想. 提交于 2019-11-30 05:06:20
I'm going to create an API which contains money amounts. I was wondering what the best practices are, or whether someone has some good or bad experiences with certain formats. should we transmit base units or minor units? (amount vs amount_cents) should we represent the numbers as integers / decimals or as strings? I've seen the following two possibilities: send amounts as a string like so: "5.85" (a string with base units) send amounts in their minor unit: 585 (an integer which expresses the amount in the minor unit) I'm going back and forth between those two. So I went out to check what

What is the python for Java's BigDecimal?

安稳与你 提交于 2019-11-30 05:01:48
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 (I think) and multiply with 100 to get dollars but I also have foreign currency so listing listing ordered by price becomes inconvenient when articles have different currencies and even are listed as price per hour or per item. So ideally I would like a class for money in python that has exchange rate, currency and what type of

Programmatically access Currency Exchange Rates from Yahoo Finance by Date

旧城冷巷雨未停 提交于 2019-11-30 04:58:38
I found the answer to this question VERY useful , but I would like to also get exchange rates for dates in the past, not just today's exchange rates. I'm writing an iPhone app that uses the exchange rate to calculate money made from sales in different countries. Here's the example from the answer mentioned above to get today's echange rate for GBP to EUR: http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=sl1d1t1ba&e=.csv Does anyone know how to do this for any other dates? THANK YOU! To retrieve historical data of currency exchange rates, you can't use Yahoo Finance. Their API only

Python - Convert currency code to its sign

杀马特。学长 韩版系。学妹 提交于 2019-11-30 04:50:47
In Python, how can I convert currency code to its sign? For example, USD would be converted to $ , and JPY would be converted to ¥ . If there isn't a generic way to do this, is there any simple dictionary of these on the Web? Thanks. Using the locale module: import locale locales=('en_AU.utf8', 'en_BW.utf8', 'en_CA.utf8', 'en_DK.utf8', 'en_GB.utf8', 'en_HK.utf8', 'en_IE.utf8', 'en_IN', 'en_NG', 'en_PH.utf8', 'en_US.utf8', 'en_ZA.utf8', 'en_ZW.utf8', 'ja_JP.utf8') for l in locales: locale.setlocale(locale.LC_ALL, l) conv=locale.localeconv() print('{ics} ==> {s}'.format(ics=conv['int_curr_symbol

Convert currency to float (and parentheses indicate negative amounts)

不想你离开。 提交于 2019-11-30 04:49:28
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: Currency 0 1.00 1 2000.00 2 -3000.00 Just add ) to the existing command, and then convert ( to - to make

How to get currency exchange rates in R

ぐ巨炮叔叔 提交于 2019-11-30 03:58:26
Are there are any R packages/functions to get exchange rates in real time, e.g. from Google Finance? Would prefer to avoid RCurl or other parsers if something's already out there. Specifically, given vectors of "from" and "to" currency symbols, I'd like to know the rates. Something like: IdealFunction(c("CAD", "JPY", "USD"), c("USD", "USD", "EUR")) You can use quantmod to get yahoo quotes. (I'm not sure how delayed yahoo FX quotes are, or how often they're updated.) library(quantmod) from <- c("CAD", "JPY", "USD") to <- c("USD", "USD", "EUR") getQuote(paste0(from, to, "=X")) # Trade Time Last

PHP/MySQL: Best money operations/storing practices?

人走茶凉 提交于 2019-11-30 03:45:51
So, I am planning to make an application (PHP/MySQL) which deals a lot with money, and I am thinking about how to store and operate with the money, referring to PHP float data type and MySQL decimal. I was thinking of two options. One of them is to operate and store money in integer cents format ($dollars * 100) in order not to deal with float inprecisions and to store it in the DB as integer too. The other one is to store in DB as decimal and to use BC Math in PHP for calculations. So I googled all the night to find out which is the best option to use and didn't find a clear answer. The only

Custom Currency symbol and decimal places using decimal.ToString(“C”) and CultureInfo

点点圈 提交于 2019-11-30 03:42:48
问题 I have a problem with decimal.ToString("C") override. Basically what I wants to do is as follows: CultureInfo usCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = usCulture; NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); LocalFormat.CurrencySymbol = "RM"; I wants to make above code a function (override ToString("C")) whereby when the following code get executed: decimal paid = Convert.ToDecimal(dr["TotalPaids"]); lblPaids.Text =