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: Freeman Gilmore
Subject: Re: rounded number to an integer?
Date: Sun, 3 Jan 2021 00:08:14 -0500



On Sat, Jan 2, 2021 at 11:10 PM Aaron Hill <lilypond@hillvisions.com> wrote:
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.
Aaron:
You may  now something that may help.   I have a denominator that is a power of 2 say 1024 i can not exceed 1024 but it can go smaller. I want the numerator to round to the closes 1/1024,    Use this example  132.527/ 1024  => 133/1024
Thank you, ƒg

;;;;
(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]