Harvey
Harvey

Reputation: 5821

How do I get mit-scheme to return a floating point number?

(/ 4 3) returns 4/3 as an answer. What is the simplest way to get 1.3...?

Upvotes: 15

Views: 5927

Answers (2)

Kyle Cronin
Kyle Cronin

Reputation: 79143

An easy way would be to make sure that one of the numbers in the calculation is already a floating-point number:

> (/ 4.0 3)
1.3333333333333333

Another way would be to use exact->inexact:

> (exact->inexact (/ 4 3))
1.3333333333333333

Upvotes: 27

akf
akf

Reputation: 39495

use

(/ 4 3.0)

Upvotes: 4

Related Questions