On Wed, Feb 2, 2011 at 10:25 AM, Oliver Peters <[email protected]> wrote: > Hello, > > I'm on Win XP with sqlite 3.7.5 and trying to get cents from euro but > sometimes > I get a strange result: > > SQLite version 3.7.5 > Enter ".help" for instructions > Enter SQL statements terminated with a " > sqlite> SELECT CAST(2.1*100 AS INTEGER); > 210 > sqlite> SELECT CAST(2.2*100 AS INTEGER); > 220 > sqlite> SELECT CAST(2.3*100 AS INTEGER); > 229 <- S T R A N G E result > sqlite> SELECT CAST(2.4*100 AS INTEGER); > 240 > sqlite> SELECT CAST(2.5*100 AS INTEGER); > 250 > sqlite> SELECT CAST(2.6*100 AS INTEGER); > 260 > sqlite> SELECT CAST(2.7*100 AS INTEGER); > 270 > sqlite> SELECT CAST(2.8*100 AS INTEGER); > 280 > sqlite> SELECT CAST(2.9*100 AS INTEGER); > 290 > sqlite> SELECT CAST(3.0*100 AS INTEGER); > 300 > sqlite> SELECT CAST(3.1*100 AS INTEGER); > 310 > sqlite> SELECT CAST(3.2*100 AS INTEGER); > 320 > sqlite> SELECT CAST(3.3*100 AS INTEGER); > 330 > sqlite> SELECT CAST(3.4*100 AS INTEGER); > 340 > sqlite>
Can you store the euro's as cents? Then you'll have the opposite problem of converting cents to euro's but that is much safer. Quick reference for further reading, http://stackoverflow.com/questions/618056/what-is-the-best-way-to-store-a-money-value-in-the-database Stephan > > Is the result for 2.3 expected behaviour (strange floating point arithmetic > reasons?) and is > > sqlite> SELECT CAST(2.3*1000 AS INTEGER)/10; > 230 > sqlite> > > a reliable way to get rid of my problem (even if the Real has 2 digits behind > the .)? > > greetings > Oliver > > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Stephan Wehner -> http://stephan.sugarmotor.org (blog and homepage) -> http://loggingit.com -> http://www.thrackle.org -> http://www.buckmaster.ca -> http://www.trafficlife.com -> http://stephansmap.org -- http://blog.stephansmap.org -> http://twitter.com/stephanwehner / @stephanwehner _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

