currency

Currency modeling in database

a 夏天 提交于 2019-11-29 10:58:21
A very naive question. I need to store currency in the database. Both the value and the code. To solve this, do people generally make 2 columns, one storing the value and other the code? Or is there an inbuilt type I can use? -thanks WW. You will need to use two columns. I would store the monetary amount in one column and the alpha currency code in another column. In some cases, you will have multiple amounts on a single row. e.g. shipping amount and tax amount may both be on the invoice record. You will need to decide if these will share the same currency or if you need two columns. You

Deprecation warning for creating attribute 'currency'

感情迁移 提交于 2019-11-29 10:01:32
I'm using Rails 3.2.3 with the money-rails gem and I've got a product model which has the following: My model class Product < ActiveRecord::Base attr_accessible :name, :price composed_of :price, :class_name => "Money", :mapping => [%w(price_cents cents), %w(currency currency_as_string)], :constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) }, :converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") } end My Test require 'spec_helper' describe Product do

NSLocale Swift 3

给你一囗甜甜゛ 提交于 2019-11-29 09:22:46
How do I get the currency symbol in Swift 3? public class Currency: NSObject { public let name: String public let code: String public var symbol: String { return NSLocale.currentLocale().displayNameForKey(NSLocaleCurrencySymbol, value: code) ?? "" } // MARK: NSObject public init(name: String, code: String) { self.name = name self.code = code super.init() } } I know NSLocale got renamed to Locale, but displayNameForKey got removed and I only seem to be able to use localizedString(forCurrencyCode: self.code) to generate the name of the currency in the current locale without being able to get its

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

烂漫一生 提交于 2019-11-29 07:22:42
问题 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 回答1: 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

How to get the default currency from the PHP Intl ( ICU library )

左心房为你撑大大i 提交于 2019-11-29 04:54:56
I use PHP, and like to know how I can get the default currency for a locale via the Internationalization extension (Wrapper for the ICU library)? Below is a script that explains, what and why. I need something to replace the getCurrCode() function with. $accepted_currencies = array('USD','EUR'); $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); if( ! empty($locale)){ Locale::setDefault($locale); $currency = getCurrCode(); if( ! in_array($currency, $accepted_currencies)){ $currency = 'USD'; } }else{ Locale::setDefault('en_US'); } $fmt = new NumberFormatter( $locale,

Cast a Double Variable to Decimal

杀马特。学长 韩版系。学妹 提交于 2019-11-29 04:21:23
问题 This will seem like a silly question to some but I need to cast a double to decimal to use as currency. Where does the M go? decimal dtot = (decimal)(doubleTotal); 回答1: You only use the M for a numeric literal, when you cast it's just: decimal dtot = (decimal)doubleTotal; Note that a floating point number is not suited to keep an exact value, so if you first add numbers together and then convert to Decimal you may get rounding errors. You may want to convert the numbers to Decimal before

How to define money amounts in an API

霸气de小男生 提交于 2019-11-29 02:54:26
问题 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

Money formatting directive in Angular

流过昼夜 提交于 2019-11-29 02:49:14
问题 I need a directive for filtering a field for currency, so a user just needs to type and the decimal is implied. Needs: Format decimal field as user types - Start at the hundredths place as the user types. So they would type "4" and see "0.04", type "42" and see "0.42", type 298023 and see "2980.23" Field must be a number Must allow negatives - Allow 0.00 as a number input Ideally would use type="number" but "type=text" is okay You should be able to clear the field to be empty. The ng-currency

Get Currency Symbol based on Country code or Country name using NSLocale

巧了我就是萌 提交于 2019-11-29 02:44:42
I want to display Currency Symbol based on Country name or country code using NSLocale I have all the country name list. suppose I have selected USA then it Return $ Currency Code : NSLocale *locale = [NSLocale currentLocale]; NSString *countryCode = [locale objectForKey: NSLocaleCountryCode]; NSString *country = [locale displayNameForKey: NSLocaleCurrencyCode value: countryCode]; You can build your own list of country codes and that country's currency symbol using the following code: Objective-C: - (void)listCountriesAndCurrencies { NSArray<NSString *> *localeIds = [NSLocale

Programmatically access Currency Exchange Rates from Yahoo Finance by Date

懵懂的女人 提交于 2019-11-29 02:38:36
问题 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!