Can't represent 2.3 correctly.

You can fix the whole thing by using 100.1 I think...

sqlite> select cast(2.3*100.1 as integer);
230

Michael D. Black
Senior Scientist
NG Information Systems
Advanced Analytics Directorate



________________________________________
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Oliver Peters [oliver....@web.de]
Sent: Wednesday, February 02, 2011 12:25 PM
To: sqlite-users@sqlite.org
Subject: EXTERNAL:[sqlite] how to get a reliable Integer from a Real?

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>

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
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to