lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rounded number to an integer?


From: Aaron Hill
Subject: Re: rounded number to an integer?
Date: Sat, 02 Jan 2021 20:10:03 -0800
User-agent: Roundcube Webmail/1.4.9

On 2021-01-02 7:38 pm, Freeman Gilmore wrote:
How do I change a rounded number (decimal number) to an integer?
Example:  (round 60.76) ==> 61.0     want  ==> 61

inexact->exact will do that.

;;;;
(inexact->exact (round 60.76))
=> 61
;;;;

For:
#(define  try  (/ (round 60.76) 64))
#(write try)
==> 0.953125
Want
==> 61/64

inexact->exact can return a rational, although it will only generate a dyadic rational, that is a rational with a power-of-two denominator. Something like 1.2 will not return 6/5, for instance.

;;;;
(inexact->exact 0.5)
=> 1/2
(inexact->exact 1.2)
=> 5404319552844595/4503599627370496
;;;;

What you need to do is use a combination of rationalize and inexact->exact:

;;;;
(rationalize (inexact->exact 1.2) 1/100)
=> 6/5
;;;;


-- Aaron Hill



reply via email to

[Prev in Thread] Current Thread [Next in Thread]