rounding fractions
Daniel Hirst <daniel.hirst@...>
I have had problems trying to round numbers to a fractional value.
Let's say I have a variable called "percent" which contains the value 72.356875421025 and I should like to round it to an accuracy of 0.01 percent. I have tried round(percent*100)/100 but this gives me 72.359999999999999 instead of the expected 72.36 I also tried round(percent*100)/round(100) but that gives the same result. Is there any way round this? (sorry no pun intended!)   Laboratoire Parole et Langage, CNRS, Universit de Provence Equipe Prosodie et Reprsentation Formelle du Langage 29 Avenue Schuman, 13621 AixenProvence cedex 1 FRANCE tel:+33 4 4295 3628 secr:+33 4 4295 3634 fax: +33 4 4259 5096 web: http://www.lpl.univaix.fr/~hirst  If (you are interested in Speech Prosody) { subscribe to the SProSIG list; } # http://www.egroups.com/group/sprosig/ 


AGUSTI XARAU <xarausuport@...>
Mensaje original
De: Daniel Hirst [mailto:daniel.hirst@...] Enviado el: mircoles, 15 de noviembre de 2000 11:11 Para: praatusers@... Asunto: [praatusers] rounding fractions I thinks.... is posible? INT(percent*100+0.5)/100 BYE


Paul Boersma <paul.boersma@...>
Daniel Hirst wrote:
I have had problems trying to round numbers to a fractional value.This number, 72.359999999999999, is the nearest 17digit representation of the 64bit floating point number nearest to 72.36. The script a = 72.36 echo 'a' gives the same result, and it is correct, because 72.36 has no exact representation in 64bit floating point. If you use this rounding for drawing the number in a picture, you can use explicit numbertostring conversion. Currently, the formula is awkward: a = round (percent * 100) a$ = "'a'" a$ = left$ (a$, length (a$)  2) + "." + right$ (a$, 2) In Praat 3.9.5, I will have added a nicer way: a$ = fixed$ (percent, 2)  Paul Boersma Institute of Phonetic Sciences, University of Amsterdam Herengracht 338, 1016CG Amsterdam, The Netherlands http://www.fon.hum.uva.nl/paul/

