1

select round(836.0) returns 836.0

How can i remove the trailing zeroes in an sqlite query.

836.00 should be 836 836.440 should be 836.44

user584263
  • 375
  • 5
  • 18

2 Answers2

2

If you want 836.44 you need a decimal return type, 836 expressed in this way will always have a .00. 836 on its own would need to be an integer and you cannot mix types in a column like that.

Your only option would be to use a string return type and remove .0*

select rtrim(rtrim(round(FLD, 2), '0'), '.')

Instead, this is best done in your presentation layer.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

For small numbers, you can use the %g option of printf(), together with round().

select round(25.999, 2); --- prints "26.0"

select printf("%g", round(25.999, 2)); --- prints "26"
mwag
  • 3,557
  • 31
  • 38
  • what qualifies as a _small number_, and why only these can be used with printf? – ajwood Sep 03 '20 at 14:32
  • I found this in the docs - The floating-point to text conversion subfunction for the built-in printf() is limited in precision to 16 significant digits or 26 significant digits if the "!" alternate-form-2 flag is used. Every IEEE-754 double can be represented exactly as a decimal floating-point value, but some doubles require more than 16 or 26 significant digits. - is that what you're referring to? – ajwood Sep 03 '20 at 14:54