BigDecimal e$B$N=$@5$N7o$G>/$7;n$7$F$$$?$N$G$9$,!“e(Bto_i
e$B$C$F$+$J$jCY$/$J$ke(B
e$B$3$H$,$”$k$h$&$G$9$M!#e(B
BigDecimal#split e$B$,$"$i$o$9M-M}?t$+$i@0?t$r5a$a$i$l$k$N$G!"e(Bto_i
e$B$,0UL#$9$k$N$O35$M0J2<$N$h$&$J$b$N$@$H9M$($i$l$^$9!#e(B
class BigDecimal
def to_i2
if nan? || infinite?
raise FloatDomainError
end
s, f, b, e = split
(s * f.to_i * b ** (e - f.size)).to_i
end
end
1.9 e$B$G$J$$$H%@%a$@$H;W$$$^$9$7!“e(BBigDecimal
e$B$K$D$$$F>$7$/$J$$$N$G!”$J$Ke(B
e$B$+4V0c$C$F$$$k$+$b$7$l$^$;$s$,!"$3$N$[$&$,B.$$$_$?$$$G!"e(B
BigDecimal(‘12.345e678901’) e$B$N$h$&$JBg$-$J?t$G$O8z2LE*$K8+$($^$9!#e(B
e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
In message “Re: [ruby-dev:38589] BigDecimal#to_i”
on Thu, 11 Jun 2009 22:39:04 +0900, Tadayoshi F.
[email protected] writes:
|BigDecimal e$B$N=$@5$N7o$G>/$7;n$7$F$$$?$N$G$9$,!“e(Bto_i e$B$C$F$+$J$jCY$/$J$ke(B
|e$B$3$H$,$”$k$h$&$G$9$M!#e(B
|1.9 e$B$G$J$$$H%@%a$@$H;W$$$^$9$7!“e(BBigDecimal e$B$K$D$$$F>$7$/$J$$$N$G!”$J$Ke(B
|e$B$+4V0c$C$F$$$k$+$b$7$l$^$;$s$,!"$3$N$[$&$,B.$$$_$?$$$G!"e(B
|BigDecimal(‘12.345e678901’) e$B$N$h$&$JBg$-$J?t$G$O8z2LE*$K8+$($^$9!#e(B
e$B%Q%C%A$r$/$@$5$C$?$i<h$j9~$_$^$9!#$U$J$P$5$s$K$3$s$J$*4j$$$re(B
e$B$9$k$N$O6Z0c$$$+$b$H$O;W$$$^$9$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