2

I want to display a number as decimal, however it keeps showing as a fraction

Example

(/ 7 9) ; --> displays as 7/9 but should be .77777

I've tried the builtin #d but it doesn't seem to work on operation results, also number->real and other variations

Alter
  • 3,332
  • 4
  • 31
  • 56

1 Answers1

2

For this, you can use the exact->inexact procedure:

(exact->inexact (/ 7 9))
=> 0.77777778
Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • That worked. I find the syntax a bit long for what seems like a fundamental task. Do you know if there is a way to show all results as decimal? – Alter Jan 19 '20 at 18:38
  • 1
    No, by default Scheme will try to do exact arithmetic. It's verbose, granted, but `exact->inexact` is the only way to go. Well, unless you switch to using decimals from the beginning: `(/ 7.0 9.0)` – Óscar López Jan 19 '20 at 18:42