--00235429e27c68c86404b72fd05b
Content-Type: text/plain; charset=UTF-8

On Mon, Jan 23, 2012 at 11:40 AM, Robert Klemme
<shortcutter / googlemail.com>wrote:

> On Mon, Jan 23, 2012 at 11:35 AM, Peter Vandenabeele
> <peter / vandenabeele.com> wrote:
> > On Mon, Jan 23, 2012 at 11:33 AM, Peter Vandenabeele <
> peter / vandenabeele.com
>
> >> Feature request:
> >>
> >> Based on this discussion, it would actually be useful to me if I could
> >> shorten this:
> >>
> >>   amount  igDecimal.new("15.5")
> >>
> >> to
> >>
> >>   amount  5.5B
>
> Bad idea IMHO because this requires a parser change and also makes all
> programs implicitly require "bigdecimal" which is usually not needed.
>
> > Maybe
> >
> > 15.5D
> >
> > is better naming (maps to "Decimal" and the %d of format string).
>
> Or
>
> amount  5.4.to_bd
> amount  5.4.to_decimal
> amount  5.4.to_dec
> amount  D(15.4)
>

When writing 15.4 ... and then calling a method on it,
it's already too late.

BD("15.4") would work though ...

1.9.3p0 :001 > def BD(number)
1.9.3p0 :002?>   BigDecimal.new(number)
1.9.3p0 :003?>   end
 nil
1.9.3p0 :004 > def BD_from_string(string)
1.9.3p0 :005?>   BigDecimal.new(string)
1.9.3p0 :006?>   end
 nil
1.9.3p0 :007 > BD(15.4)
NameError: uninitialized constant BigDecimal
    from (irb):2:in `BD'
    from (irb):7
    from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :008 > require 'bigdecimal'
 true
1.9.3p0 :009 > BD(15.4)
ArgumentError: can't omit precision for a Rational.
    from (irb):2:in `new'
    from (irb):2:in `BD'
    from (irb):9
    from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :010 > BD_from_string("15.4")
 #<BigDecimal:96787bc,'0.154E2',18(18)>

Peter

--00235429e27c68c86404b72fd05b--