zoukankan      html  css  js  c++  java
  • 关于postgresql中numeric和decimal的精度和标度问题

    精度即数的有效数字个数

    2.5的有效数字个数是2,但是053.2的有效数字个数是3

    标度是小数点的位数

    例如numeric(2,1),即这个数必须是两位,并且小数后面最多有一位,多出来的小数会被四舍五入

    可以很容易的确定出numeric的范围,即-10(精度-标度)到10(精度-标度)次方之间,不包括两头

    create table test (num numeric(2,1));
    insert into test values (2.2);
     num 
    -----
     2.2
    insert into test values (2.26);
     num 
    -----
     2.3
    insert into test values (10);
    ERROR:  numeric field overflow
    DETAIL:  A field with precision 2, scale 1 must round to an absolute value less than 10^1.
  • 相关阅读:
    函数之返回值
    函数之初识函数
    三元运算符
    枚举enumerate
    模块
    迭代器
    斐波那契
    leetcode155 最小栈
    leetcode94 二叉树的中序遍历
    leetcode20 有效的括号
  • 原文地址:https://www.cnblogs.com/monkey6/p/12421181.html
Copyright © 2011-2022 走看看