Forum: Ruby-core [Closed] printf("%.60f\n", 0.1r) shows 0.10000000000000000555111512312578270211815834045410156250000

F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2014-08-18 10:07
(Received via mailing list)
Issue #10136 has been updated by Nobuyoshi Nakada.

Status changed from Open to Closed
% Done changed from 0 to 100

Applied in changeset r47214.

----------
sprintf.c: rational 'f' format

* sprintf.c (rb_str_format): support rational 'f' format.
  [ruby-core:64382] [Bug #10136]

----------------------------------------
Bug #10136: printf("%.60f\n", 0.1r) shows
0.100000000000000005551115123125782702118158340454101562500000
https://bugs.ruby-lang.org/issues/10136#change-48391

* Author: Akira Tanaka
* Status: Closed
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: ruby 2.2.0dev (2014-08-15 trunk 47187) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
printf shows 0.1r (rational) not 0.1 as follows.

```
% ./ruby -ve 'printf "%.60f\n", 0.1r'
ruby 2.2.0dev (2014-08-15 trunk 47187) [x86_64-linux]
0.100000000000000005551115123125782702118158340454101562500000
```

It seems printf converts the rational argument to a float.

I expect 0.100000000000000000000000000000000000000000000000000000000000
instead of
0.100000000000000005551115123125782702118158340454101562500000.
This topic is locked and can not be replied to.