Open
Description
library(DBI)
data <- 0.0027392760273972603
sql <- dbQuoteLiteral(ANSI(), data)
sql
#> <SQL> 0.00273927602739726
as.numeric(sql) - data
#> [1] -4.336809e-19
sql_exp <- sprintf("%.17e", data)
sql_exp
#> [1] "2.73927602739726037e-03"
as.numeric(sql_exp) - data
#> [1] 0
Created on 2022-12-09 with reprex v2.0.2
We could use sprintf("%.17e")
as in the reprex to always convert to exponential notation with enough decimal numbers.
@hannes: Are you aware of databases that would complain about numbers passed in exponential notation in situations when they wouldn't complain about decimal numbers?