Salut Thibaut! Il est vraiment que j'aurai dû le mentionner dès le début, c'est une erreur de ma part et je m'en excuse. Je travaille avec Oracle et non MySql. Par contre j'utilise bien le float comme type. Il est cependant probable que le comportement soit identique, je vais m'y pencher.
En tout cas merci pour le lien sur les "extreme floating", ça m'a l'air très intéressant. Je me le garde dans un coin car la je n'ai pas trop le temps d'y jeter un oeil ;-) Encore merci! ps: si tu le vois, passe le bonjour à ton frère ,-) Mike -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Thibaut Barrère Sent: jeudi 3 juillet 2008 23:20 To: Railsfrance Subject: [RailsFr] Re: Problème de float Hello Mike, peut-être utilises-tu le type float pour ta valeur en base de données (MySQL j'imagine ?) MySQL stocke les "float" sur 4 octets (cf http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html) ce qui ne permet pas de mémoriser un décimal avec une grande précision. Dans ton cas, si Price est un model avec :price_as_float une colonne en float, tu auras: >> Price.create(:price_as_float => 96.20825).reload.price_as_float => 96.2083 (et non 96.20825) Côté base tu auras un: INSERT INTO prices (price_as_float) VALUES(96.20825) qui stockera au final 96.2083 et non 96.20825 Si tu dois stocker des chiffres avec une meilleure précision, tu peux t'orienter vers t.decimal :price_as_decimal, :precision => 30, :scale => 20 (précision et scale à adapter en fonction de tes besoins - regarde la doc MySQL de près). Ex: >> Price.create(:price_as_decimal => 96.20825).reload.price_as_decimal >> == 96.20825 => true Si tu veux tout savoir sur le pourquoi du comment (stockage en mémoire des flottants), je pense que tu trouveras l'article suivant intéressant: http://www.codeproject.com/KB/dotnet/ExtremeFloatingPoint1.aspx good luck! Thibaut Barrère / LoGeek -- http://blog.logeek.fr - learning content for developers http://evolvingworker.com - tools for a better day http://faire-autrement.fr - la simplicité au quotidien --------------------- Internet communications are not secure or error free and the contents of any attachment to this e-mail may contain software viruses or other defect which might affect your own computer system. RBC Dexia Investor Services Bank S.A. does not accept liability and/or responsibility for any damage or loss which may occur or be sustained consequently. The recipient is responsible for virus checks before opening any attachment. The information contained in this e-mail may be privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any disclosure, use or copying of the information contained herein is strictly prohibited and may be unlawful. If you receive this in error, please contact the sender and delete the e-mail. --------------------- An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. --------------------- --------------------- Internet communications are not secure or error free and the contents of any attachment to this e-mail may contain software viruses or other defect which might affect your own computer system. RBC Dexia Investor Services Bank S.A. does not accept liability and/or responsibility for any damage or loss which may occur or be sustained consequently. The recipient is responsible for virus checks before opening any attachment. The information contained in this e-mail may be privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any disclosure, use or copying of the information contained herein is strictly prohibited and may be unlawful. If you receive this in error, please contact the sender and delete the e-mail. --------------------- An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. --------------------- --~--~---------~--~----~------------~-------~--~----~ Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups. Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse [email protected] Pour résilier votre abonnement envoyez un e-mail à l'adresse [EMAIL PROTECTED] -~----------~----~----~----~------~----~------~--~---
