[R] specify the number of decimal numbers

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Thu May 14 17:22:32 CEST 2009


James W. MacDonald wrote:
>
>
> Wacek Kusnierczyk wrote:
>> (Ted Harding) wrote:
>>> On 14-May-09 12:27:40, Wacek Kusnierczyk wrote:
>>>  
>>>> ... but remember that sprintf introduces excel bugs into r (i.e.,
>>>> rounding is not done according to the  IEC 60559 standard, see
>>>> ?round):
>>>>
>>>>     ns = c(0.05, 0.15)
>>>>     round(ns, 1)
>>>>     # 0.0 0.2
>>>>     as.numeric(sprintf('%.1f', ns))
>>>>     # 0.1 0.1
>>>> vQ
>>>>     
>>> True! And thanks for importing that point into the discussion.
>>>   
>>
>> said but true, true but sad.  i have already raised the issue on this
>> list earlier, but to no response.  apparently, this sort of excel bug in
>> r is an intentional feature, so you may not get it improved anytime
>> soon.  unless you submit a patch and get it accepted, that is.
>
> Have you brought this 'issue' up with the Perl people as well?
>
> perl -e 'print sprintf("%.1f", 0.05) . "\n";'
> 0.1
> perl -e 'print sprintf("%.1f", 0.15) . "\n";'
> 0.1
>

do they make pompous claims about their software and disregarding claims
about others' as well?

vQ




More information about the R-help mailing list