为什么"M"表示出现在Clojure MySQL查询结果中 [英] Why does "M" appear in Clojure MySQL Query Results

查看:51
本文介绍了为什么"M"表示出现在Clojure MySQL查询结果中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Clojure查询,该查询返回一行,这是返回的行(地图)的部分打印输出.

I have a Clojure query that returns a row, and here is a partial printout of the returned row (map).

({:employer_percent 0.00M, ... :premium 621.44M, ...})

这两个列在mysql表中分别是十进制(5,2)和十进制(7,2).

These two columns are decimal(5,2) and decimal(7,2) respectively in the mysql table.

为什么每个值的末尾都有一个"M"后缀?这是形成并执行查询的代码.

Why is there an 'M' suffix at the end of each of these values? Here is the code that forms and executes the query.

    (def db {:classname "com.mysql.jdbc.Driver"
             :subprotocol "mysql"
             :subname "//system/app"
             :user "app-user"
             :password "pwrd"})

  (defn get-recent-gic-rows
  [search-date lt-toggle]
  (let [query (if (= 0 lt-toggle)
   (str "select g.* from gic_employees g where g.processed_date <= '" search-date "' order by g.processed_date desc limit 1  ")
   (str "select g.* from gic_employees g where g.processed_date <  '" search-date "' order by g.processed_date desc limit 1  "))]

        (j/query db
             [query])))

推荐答案

M后缀表示数字为BigDecimal.您可以在REPL中查看

M suffix means that the number is BigDecimal. You can check this in REPL

user=> (class 1)
java.lang.Long
user=> (class 1.0)
java.lang.Double
user=> (class 1M)
java.math.BigDecimal

由于您的数据库列类型为decimal(5,2)decimal(7,2),将数字转换为floatdouble是不安全的,因为这些浮点类型不能代表decimal(5,2)decimal(7,2)准确.

Since your database column type is decimal(5,2) and decimal(7,2), it's not safe to convert the numbers to float or double because those floating point type can't represent all the numbers of decimal(5,2) or decimal(7,2) accurately.

您可以使用关键字"floating point inaccuracy"(浮点精度)在Google中进行搜索. Stackoverflow中也有大量的文章和问答.

You can google with the keyword "floating point inaccuracy". There are tons of articles and Q&As, also within Stackoverflow.

这篇关于为什么"M"表示出现在Clojure MySQL查询结果中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆