7

Does there exist for SQLite something similar as the TRUNCATE function from MySQL?

SELECT TRUNCATE(1.999,1); # 1.9
sid_com
  • 24,137
  • 26
  • 96
  • 187

3 Answers3

9

You can do this numerically by converting to an int and back:

select cast((val * 10) as int) / 10.0

You can do this using round() and subtraction:

select round(val - 0.1/2, 1)

Or, as another answer suggests, you can convert to a string.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
5

There is no built-in function that would do this directly. However, you can treat the number as a string, search for the decimal separator, and count characters from that:

SELECT substr(1.999, 1, instr(1.999, '.') + 1);

(This does not work for integers.)

CL.
  • 173,858
  • 17
  • 217
  • 259
0

To work for integers:

SELECT substr(100 * 1.0, 1, instr(100 * 1.0, '.') + 1);
Obsidian
  • 3,719
  • 8
  • 17
  • 30
Sergio
  • 1