Tag: 货币

我可以在Rails 4应用程序中使用带有条带的活动商家中传递不同的货币吗?

我正在开发Rails 4应用程序,用户可以通过应用程序订阅一次性付费。 对于订阅,请使用带有条带的Active Merchant,现在用户现在支付50美元并成功完成付款。 下面的代码: ActiveMerchant::Billing::Base.mode = :test transaction = ActiveMerchant::Billing::StripeGateway.new(:login => Rails.application.secrets.stripe_secret_key) paymentInfo = ActiveMerchant::Billing::CreditCard.new( :number => purchage_params[:card_holder_number], :month => purchage_params[:expiry_month], :year => purchage_params[:expiry_year], :verification_value => purchage_params[:cvv]) purchaseOptions = {:billing_address => { :name => purchage_params[:card_holder_name], :currency => @country.currency, :address1 => session[:address], :city => session[:city], :state => @region.name, :zip => session[:zip_postal] }} response = transaction.purchase((amount […]

如何用符号使用money-rails显示价格

鉴于这个简单的Money对象查询 Money.new(1000, “USD”).to_s => “10.00” 如何用符号显示值? 我知道我可以调用money_object.symbol但有些货币会将符号放在值之前和之后。 我很确定应该有一些简单的方法吗? 通过阅读文档找不到它。

Rails 3 – 多种货币

如果我这样做: number_to_currency(100,:locale=>’en-GB’) 我希望得到这样的东西: £100.00 但相反,我得到了 $100 如果我传入语言环境,这是相同的:en,’fr-FR’或其他。 Rails是否有基于区域设置的默认货币列表,或者我是否必须自己为地球上的每个国家设置I18映射? 任何帮助赞赏。 托宾

Ruby字符串与美元“钱”转换为数字

目前是否有能够接受字符串的gem,为此目的以美元为单位,并将它们转换为数字? 一些例子是: “7,600美元”将变成7600 “5500”将变成5500 我知道在“5500”示例中我可以做“5500”.to_i,但导入的电子表格不一致,有些包括逗号和美元符号,而有些则没有。 在Ruby中有一个很好的处理方式吗? 我尝试过类似money_string.scan(/\d/).join这似乎很好,只是担心我会遇到我还没有找到的边缘情况,比如小数位。

处理Ruby on Rails中的国际货币输入

我有一个处理货币输入的应用程序 。 但是,如果你在美国,你可以输入一个12,345.67的数字; 在法国,它可能是12.345,67 。 在Rails中,有一种简单的方法可以使货币条目适应区域设置吗? 请注意,我不是在寻找货币的显示(ala number_to_currency ),我正在寻找与某人输入货币字符串并将其转换为小数的人。

使用表单选择使用Money gem设置货币

我已经在这个工作了几个小时,但我无法弄清楚这一个。 我愿意让用户为他填写表格的价格选择相应的货币。 我正在使用Money Gem(https://github.com/RubyMoney/money)。 所有值都设置正确但不是仅通过表单发送的设置为其默认值(USD)的货币。 我想这是我对Moneygem缺乏经验。 在我的模型中: require ‘money’ composed_of :price_per_unit, :class_name => “Money”, :mapping => [%w(cents_per_unit cents), %w(currency currency_as_string)], :constructor => Proc.new { |cents_per_unit, currency| Money.new(cents_per_unit || 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”) } composed_of :total_price, :class_name => “Money”, :mapping […]

用于创建属性“货币”的弃用警告

我正在使用Rails 3.2.3和money-rails gem,我有一个产品型号,其中包含以下内容: 我的模特 class Product “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 我的测试 require ‘spec_helper’ describe Product do context “testing money gem” do it […]

如何防止Ruby钱浮点错误

我正在使用带有money-rails gem的Rails来处理钱列。 有没有办法防止浮点错误发生? (即使是黑客也会这样做,我只是想确保没有这样的错误呈现给最终用户) Rspec示例案例: it “correctly manipulates simple money calculations” do # Money.infinite_precision = false or true i’ve tried both start_val = Money.new(“1000”, “EUR”) expect(start_val / 30 * 30).to eq start_val end 结果 Failure/Error: expect(start_val / 30 * 30).to eq start_val expected: # got: # (compared using ==) Diff: @@ -1,2 +1,2 @@ -# […]

Ruby:将美元(String)转换为美分(整数)

如何将美元金额(如”5.32″或”100″的字符串转换为美分(如532或10000的整数金额? 我有一个解决方案如下: dollar_amount_string = “5.32” dollar_amount_bigdecimal = BigDecimal.new(dollar_amount_string) cents_amount_bigdecimal = dollar_amount_bigdecimal * BigDecimal.new(100) cents_amount_int = cents_amount_bigdecimal.to_i 但它似乎很不稳定。 我想确定,因为这将是PayPal API的输入。 我也尝试了金钱gem,但它不能把字符串作为输入。

Rails:money gem将所有金额转换为零

我正在尝试使用money gem在我的应用程序中处理货币,但我遇到了一个奇怪的错误。 这就是我在“记录”模型中的含义: composed_of :amount, :class_name => “Money”, :mapping => [%w(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”) } amount是一个整数。 当我创建一个新记录时,它会忽略我在amount字段中输入的任何值,并将其默认为0.我需要在表单中添加一些内容吗? 我使用的是rails 3.0.3,而money gem版本是3.5.5