值范围是否取决于数据类型的大小? [英] Is Range of value depends upon Size of datatype?

查看:29
本文介绍了值范围是否取决于数据类型的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

float 的大小为 4 个字节,long 的大小为 8 个字节.
因此,float 的大小小于 long 的大小.但是,浮动范围大于长.

float have size of 4 bytes and long have size of 8 bytes.
So, size of float is smaller than size of long. but, range of float is greater than long.

十进制和双精度相同.

数据类型

  +----------+------------+----------------------+
  | Data Type|   Size     |        Range         |
  +----------+------------+----------------------+
  |  long    | 8 bytes    |-9.22e18 .. 9.22e18   |
  |  float   | 4 bytes    |-3.40e38 .. 3.40e38   |
  |  decimal | 16 bytes   |-7.92e28 .. 7.92e28   |
  |  double  | 8 bytes    |-1.80e308 .. 1.80e308 |
  +----------+------------+----------------------+

示例:

        decimal f = 10000000000000000000.0m;            //takes 16 bytes
        double d = 10000000000000000000000000000.0d;   //takes 8 bytes

所以,double 比decimal 可以容纳更大的值并且占用更少的大小.为什么?

So, double can hold greater value and takes less size than decimal.Why?

推荐答案

因为 double 用于指数的位比十进制多.

Because double has devoted more bits to the exponent than the decimal has.

这篇关于值范围是否取决于数据类型的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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