BigDecimal 小数位的处理(RoundingMode)

前言:

在日常项目开发中,接触小数是常有的事情,而产品对于小数的处理,在不同的业务中有不同的定义,比如四舍五入、截取、向上舍位、向下舍位等等场景,面对如此多的场景,你是否会束手无策?或者说自己去研究怎么实现?其实 Java 已经给我们提供了一个枚举类 RoundingMode,RoundingMode 共有 8 种舍位方式,本篇我们来逐个分析。

RoundingMode 枚举类源码如下:

package java.math;/**** @see     BigDecimal* @see     MathContext* @author  Josh Bloch* @author  Mike Cowlishaw* @author  Joseph D. Darcy* @since 1.5*/
public enum RoundingMode {/*** Rounding mode to round away from zero.  Always increments the* digit prior to a non-zero discarded fraction.  Note that this* rounding mode never decreases the magnitude of the calculated* value.**<p>Example:*<table border>* <caption><b>Rounding mode UP Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code UP} rounding*<tr align=right><td>5.5</td>  <td>6</td>*<tr align=right><td>2.5</td>  <td>3</td>*<tr align=right><td>1.6</td>  <td>2</td>*<tr align=right><td>1.1</td>  <td>2</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-2</td>*<tr align=right><td>-1.6</td> <td>-2</td>*<tr align=right><td>-2.5</td> <td>-3</td>*<tr align=right><td>-5.5</td> <td>-6</td>*</table>*/UP(BigDecimal.ROUND_UP),/*** Rounding mode to round towards zero.  Never increments the digit* prior to a discarded fraction (i.e., truncates).  Note that this* rounding mode never increases the magnitude of the calculated value.**<p>Example:*<table border>* <caption><b>Rounding mode DOWN Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code DOWN} rounding*<tr align=right><td>5.5</td>  <td>5</td>*<tr align=right><td>2.5</td>  <td>2</td>*<tr align=right><td>1.6</td>  <td>1</td>*<tr align=right><td>1.1</td>  <td>1</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-1</td>*<tr align=right><td>-1.6</td> <td>-1</td>*<tr align=right><td>-2.5</td> <td>-2</td>*<tr align=right><td>-5.5</td> <td>-5</td>*</table>*/DOWN(BigDecimal.ROUND_DOWN),/*** Rounding mode to round towards positive infinity.  If the* result is positive, behaves as for {@code RoundingMode.UP};* if negative, behaves as for {@code RoundingMode.DOWN}.  Note* that this rounding mode never decreases the calculated value.**<p>Example:*<table border>* <caption><b>Rounding mode CEILING Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code CEILING} rounding*<tr align=right><td>5.5</td>  <td>6</td>*<tr align=right><td>2.5</td>  <td>3</td>*<tr align=right><td>1.6</td>  <td>2</td>*<tr align=right><td>1.1</td>  <td>2</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-1</td>*<tr align=right><td>-1.6</td> <td>-1</td>*<tr align=right><td>-2.5</td> <td>-2</td>*<tr align=right><td>-5.5</td> <td>-5</td>*</table>*/CEILING(BigDecimal.ROUND_CEILING),/*** Rounding mode to round towards negative infinity.  If the* result is positive, behave as for {@code RoundingMode.DOWN};* if negative, behave as for {@code RoundingMode.UP}.  Note that* this rounding mode never increases the calculated value.**<p>Example:*<table border>* <caption><b>Rounding mode FLOOR Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code FLOOR} rounding*<tr align=right><td>5.5</td>  <td>5</td>*<tr align=right><td>2.5</td>  <td>2</td>*<tr align=right><td>1.6</td>  <td>1</td>*<tr align=right><td>1.1</td>  <td>1</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-2</td>*<tr align=right><td>-1.6</td> <td>-2</td>*<tr align=right><td>-2.5</td> <td>-3</td>*<tr align=right><td>-5.5</td> <td>-6</td>*</table>*/FLOOR(BigDecimal.ROUND_FLOOR),/*** Rounding mode to round towards {@literal "nearest neighbor"}* unless both neighbors are equidistant, in which case round up.* Behaves as for {@code RoundingMode.UP} if the discarded* fraction is &ge; 0.5; otherwise, behaves as for* {@code RoundingMode.DOWN}.  Note that this is the rounding* mode commonly taught at school.**<p>Example:*<table border>* <caption><b>Rounding mode HALF_UP Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code HALF_UP} rounding*<tr align=right><td>5.5</td>  <td>6</td>*<tr align=right><td>2.5</td>  <td>3</td>*<tr align=right><td>1.6</td>  <td>2</td>*<tr align=right><td>1.1</td>  <td>1</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-1</td>*<tr align=right><td>-1.6</td> <td>-2</td>*<tr align=right><td>-2.5</td> <td>-3</td>*<tr align=right><td>-5.5</td> <td>-6</td>*</table>*/HALF_UP(BigDecimal.ROUND_HALF_UP),/*** Rounding mode to round towards {@literal "nearest neighbor"}* unless both neighbors are equidistant, in which case round* down.  Behaves as for {@code RoundingMode.UP} if the discarded* fraction is &gt; 0.5; otherwise, behaves as for* {@code RoundingMode.DOWN}.**<p>Example:*<table border>* <caption><b>Rounding mode HALF_DOWN Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code HALF_DOWN} rounding*<tr align=right><td>5.5</td>  <td>5</td>*<tr align=right><td>2.5</td>  <td>2</td>*<tr align=right><td>1.6</td>  <td>2</td>*<tr align=right><td>1.1</td>  <td>1</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-1</td>*<tr align=right><td>-1.6</td> <td>-2</td>*<tr align=right><td>-2.5</td> <td>-2</td>*<tr align=right><td>-5.5</td> <td>-5</td>*</table>*/HALF_DOWN(BigDecimal.ROUND_HALF_DOWN),/*** Rounding mode to round towards the {@literal "nearest neighbor"}* unless both neighbors are equidistant, in which case, round* towards the even neighbor.  Behaves as for* {@code RoundingMode.HALF_UP} if the digit to the left of the* discarded fraction is odd; behaves as for* {@code RoundingMode.HALF_DOWN} if it's even.  Note that this* is the rounding mode that statistically minimizes cumulative* error when applied repeatedly over a sequence of calculations.* It is sometimes known as {@literal "Banker's rounding,"} and is* chiefly used in the USA.  This rounding mode is analogous to* the rounding policy used for {@code float} and {@code double}* arithmetic in Java.**<p>Example:*<table border>* <caption><b>Rounding mode HALF_EVEN Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code HALF_EVEN} rounding*<tr align=right><td>5.5</td>  <td>6</td>*<tr align=right><td>2.5</td>  <td>2</td>*<tr align=right><td>1.6</td>  <td>2</td>*<tr align=right><td>1.1</td>  <td>1</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>-1</td>*<tr align=right><td>-1.6</td> <td>-2</td>*<tr align=right><td>-2.5</td> <td>-2</td>*<tr align=right><td>-5.5</td> <td>-6</td>*</table>*/HALF_EVEN(BigDecimal.ROUND_HALF_EVEN),/*** Rounding mode to assert that the requested operation has an exact* result, hence no rounding is necessary.  If this rounding mode is* specified on an operation that yields an inexact result, an* {@code ArithmeticException} is thrown.*<p>Example:*<table border>* <caption><b>Rounding mode UNNECESSARY Examples</b></caption>*<tr valign=top><th>Input Number</th>*    <th>Input rounded to one digit<br> with {@code UNNECESSARY} rounding*<tr align=right><td>5.5</td>  <td>throw {@code ArithmeticException}</td>*<tr align=right><td>2.5</td>  <td>throw {@code ArithmeticException}</td>*<tr align=right><td>1.6</td>  <td>throw {@code ArithmeticException}</td>*<tr align=right><td>1.1</td>  <td>throw {@code ArithmeticException}</td>*<tr align=right><td>1.0</td>  <td>1</td>*<tr align=right><td>-1.0</td> <td>-1</td>*<tr align=right><td>-1.1</td> <td>throw {@code ArithmeticException}</td>*<tr align=right><td>-1.6</td> <td>throw {@code ArithmeticException}</td>*<tr align=right><td>-2.5</td> <td>throw {@code ArithmeticException}</td>*<tr align=right><td>-5.5</td> <td>throw {@code ArithmeticException}</td>*</table>*/UNNECESSARY(BigDecimal.ROUND_UNNECESSARY);// Corresponding BigDecimal rounding constantfinal int oldMode;/*** Constructor** @param oldMode The {@code BigDecimal} constant corresponding to*        this mode*/private RoundingMode(int oldMode) {this.oldMode = oldMode;}/*** Returns the {@code RoundingMode} object corresponding to a* legacy integer rounding mode constant in {@link BigDecimal}.** @param  rm legacy integer rounding mode to convert* @return {@code RoundingMode} corresponding to the given integer.* @throws IllegalArgumentException integer is out of range*/public static RoundingMode valueOf(int rm) {switch(rm) {case BigDecimal.ROUND_UP:return UP;case BigDecimal.ROUND_DOWN:return DOWN;case BigDecimal.ROUND_CEILING:return CEILING;case BigDecimal.ROUND_FLOOR:return FLOOR;case BigDecimal.ROUND_HALF_UP:return HALF_UP;case BigDecimal.ROUND_HALF_DOWN:return HALF_DOWN;case BigDecimal.ROUND_HALF_EVEN:return HALF_EVEN;case BigDecimal.ROUND_UNNECESSARY:return UNNECESSARY;default:throw new IllegalArgumentException("argument out of range");}}
}

8种舍位模式含义解析:

  • RoundingMode.UP:正数向上舍位,负数向下舍位。
  • RoundingMode.DOWN:直接保留指定位数数字,可以理解为截取。
  • RoundingMode.CEILING:直译是天花板的意思,正数的效果如同 RoundingMode.UP,负数的效果如同 RoundingMode.DOWN。
  • RoundingMode.FLOOR:直译是地板的意思,和 RoundingMode.CEILING 刚好相反,正数的效果如同 RoundingMode.DOWN,负数的效果如同 RoundingMode.UP。
  • RoundingMode.HALF_UP:就是比较常见的四舍五入。
  • RoundingMode.HALF_DOWN:五舍六入。
  • RoundingMode.HALF_EVEN:指定位数后面的小数是5,且5后面有数字且这些数字不全部为0,则进一位,否则看5前面的一位,如果是奇数就进一位,如果是偶数则不进位,其他情况四舍五入。
  • RoundingMode.UNNECESSARY:指定位数后没有数字或者全部是0,否则会抛出异常。

RoundingMode.UP 验证:

BigDecimal bigDecimal1 = new BigDecimal("1.235");
BigDecimal up1 = bigDecimal1.setScale(2, RoundingMode.UP);
BigDecimal bigDecimal2 = new BigDecimal("-1.233");
BigDecimal up2 = bigDecimal2.setScale(2, RoundingMode.UP);
System.out.println("up1:" + up1);
System.out.println("up2:" + up2);

执行结果:

up1:1.24
up2:-1.24

正数向上舍位,负数向下舍位,符合预期。

RoundingMode.HALF_DOWN 验证:

BigDecimal down = new BigDecimal("1.235").setScale(2, RoundingMode.DOWN);
System.out.println("down:" + down);

执行结果:

down:1.23

截取直接保留指定位数数字,符合预期。

RoundingMode.CEILING 验证:

BigDecimal ceilingOne = new BigDecimal("1.235").setScale(2, RoundingMode.CEILING);
BigDecimal ceilingTwo = new BigDecimal("-1.235").setScale(2, RoundingMode.CEILING);
System.out.println("ceilingOne:" + ceilingOne);
System.out.println("ceilingTwo:" + ceilingTwo);

执行结果:

ceilingOne:1.24
ceilingTwo:-1.23

正数向上舍位,负数直接截取,符合预期。

RoundingMode.FLOOR 验证:

BigDecimal floorOne = new BigDecimal("1.235").setScale(2, RoundingMode.FLOOR);
BigDecimal floorTwo = new BigDecimal("-1.235").setScale(2, RoundingMode.FLOOR);
System.out.println("floorOne:" + floorOne);
System.out.println("floorTwo:" + floorTwo);

执行结果:

floorOne:1.23
floorTwo:-1.24

正数截取,负数向下舍位,符合预期。

RoundingMode.HALF_UP 验证:

BigDecimal halfUpOne = new BigDecimal("1.235").setScale(2, RoundingMode.HALF_UP);
BigDecimal halfUpTwo = new BigDecimal("1.234").setScale(2, RoundingMode.HALF_UP);
System.out.println("halfUpOne:" + halfUpOne);
System.out.println("halfUpTwo:" + halfUpTwo);

执行结果:

halfUpOne:1.24
halfUpTwo:1.23

四舍五入,符合预期。

RoundingMode.HALF_EVEN 验证:

BigDecimal halfEvenOne = new BigDecimal("1.2351").setScale(2, RoundingMode.HALF_EVEN);
BigDecimal halfEvenTwo = new BigDecimal("1.2250").setScale(2, RoundingMode.HALF_EVEN);
BigDecimal halfEvenThree = new BigDecimal("1.2350").setScale(2, RoundingMode.HALF_EVEN);
BigDecimal halfEvenFour = new BigDecimal("1.2450").setScale(2, RoundingMode.HALF_EVEN);
BigDecimal halfEvenFive = new BigDecimal("1.244").setScale(2, RoundingMode.HALF_EVEN);
BigDecimal halfEvenSix = new BigDecimal("1.246").setScale(2, RoundingMode.HALF_EVEN);
System.out.println("halfEvenOne:" + halfEvenOne);
System.out.println("halfEvenTwo:" + halfEvenTwo);
System.out.println("halfEvenThree:" + halfEvenThree);
System.out.println("halfEvenFour:" + halfEvenFour);
System.out.println("halfEvenFive:" + halfEvenFive);
System.out.println("halfEvenSix:" + halfEvenSix);

执行结果:

halfEvenOne:1.24
halfEvenTwo:1.22
halfEvenThree:1.24
halfEvenFour:1.24
halfEvenFive:1.24
halfEvenSix:1.25

符合预期。

RoundingMode.HALF_EVEN 验证:

BigDecimal unnecessaryOne = new BigDecimal("1.240").setScale(2, RoundingMode.UNNECESSARY);
System.out.println("unnecessaryOne:" + unnecessaryOne);
BigDecimal unnecessaryTwo = new BigDecimal("1.2401").setScale(2, RoundingMode.UNNECESSARY);
System.out.println("unnecessaryTwo:" + unnecessaryTwo);

执行结果:

unnecessaryOne:1.24
Exception in thread "main" java.lang.ArithmeticException: Rounding necessaryat java.math.BigDecimal.commonNeedIncrement(BigDecimal.java:4148)at java.math.BigDecimal.needIncrement(BigDecimal.java:4204)at java.math.BigDecimal.divideAndRound(BigDecimal.java:4112)at java.math.BigDecimal.setScale(BigDecimal.java:2452)at java.math.BigDecimal.setScale(BigDecimal.java:2386)at com.zt.dc.portal.admin.web.service.impl.satisfaction.SatisfactionEvaluationServiceImpl.main(SatisfactionEvaluationServiceImpl.java:262)

一个正常输出,一个抛出异常,符合预期。

总结:本文对 RoundingMode 共有 8 种舍位方式进行了详细分析验证,希望可以帮助到有需要的小伙伴。

欢迎提出建议及对错误的地方指出纠正。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/858405.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【算法】优先级队列-基础与应用

优先级队列&#xff08;Priority Queue&#xff09;是一种特殊的队列类型&#xff0c;它允许在其元素中分配优先级。与传统的先进先出&#xff08;FIFO&#xff09;队列不同&#xff0c;优先级队列中元素的出队顺序取决于它们的优先级。优先级较高的元素会被优先处理&#xff0…

IOS Swift 从入门到精通: 结构体的访问控制、静态属性和惰性

文章目录 初始化器引用当前实例惰性属性静态属性和方法访问控制总结初始化器 初始化器是一种特殊方法,可提供创建结构体的不同方式。所有结构体都默认带有一个初始化器,称为成员初始化器- 它会要求您在创建结构体时为每个属性提供一个值。 User如果我们创建一个具有一个属性…

windows桌面运维---第八天

1、如何判断环路&#xff1a; 1、执行ping命令&#xff1a;网络测试时发现丢包严重&#xff0c;可能是环路引起的 2、监控MAC地址漂移&#xff1a;频繁的MAC漂移是环路的一个迹象。 3、通过display interface brief | include up命令&#xff0c;查看所有UP接口下的流量 2、…

【Qt笔记①】帮助文档、窗口、按钮、信号和槽、lambda表达式

学习第一天&#xff1a;2024-3-9 文章目录 Qt creator 快捷键帮助文档默认生成的main.cpp逐行解释核心类帮助文档的查阅方法-①代码创建按钮第一个第二个对窗口的其他设置 对象树窗口坐标系信号和槽&#xff08;优点&#xff1a;松散耦合&#xff09;帮助文档的查阅方法-②找信…

价格减免(Lc2288)——模拟

句子 是由若干个单词组成的字符串&#xff0c;单词之间用单个空格分隔&#xff0c;其中每个单词可以包含数字、小写字母、和美元符号 $ 。如果单词的形式为美元符号后跟着一个非负实数&#xff0c;那么这个单词就表示一个 价格 。 例如 "$100"、"$23" 和 …

轨迹规划系列之S型速度曲线绝对值定位功能块(Codesys源代码)

1、轨迹规划的作用 轨迹规划的作用(前馈速度+位置插补)-CSDN博客文章浏览阅读13次。轨迹规划可以产生运动控制系统位置闭环控制所需要的前馈速度和插补位置值。前馈速度+PID位置闭环控制典型应用可以参考下面文章链接:1、S7-1200PLC和V90伺服通过工艺对象实现定位控制S7-1200…

Java中的加密与解密:实现安全的数据传输

Java中的加密与解密&#xff1a;实现安全的数据传输 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;在当今信息安全至关重要的时代&#xff0c;保护数据的安全性…

表驱动法 -优化逻辑分支

表驱动法 -优化逻辑分支 定义 表驱动法&#xff08;Table-Driven Approach&#xff09;是一种编程模式&#xff0c;可以将输入变量作为直接或间接索引在表里查找所需的结果或处理函数&#xff0c;而不使用逻辑语句&#xff08;if-else 和 switch-case&#xff09;。索引表可以…

VMware与windows的共享文件夹没找到怎么办?

如果这样子添加&#xff0c;在ubuntu中还是没能找到。开机后有的时候仍然未发现共享文件夹。 二、解决办法 使用如下指令&#xff1a; sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other /mnt/hgfs/ 是挂载点&#xff0c;也可以指定其它挂载点 -o allow_other…

DHCP原理1-单个局域网出现多个DHCP服务器会发生什么

1. 背景 DHCP全称是Dynamic Host Configuration Protocol。其协议标准是RFC1541&#xff08;已被RFC2131取代&#xff09;&#xff0c;主要实现服务器向客户端动态分配IP地址&#xff08;如IP地址、子网掩码、网关、DNS&#xff09;和配置信息。其系统架构是标准的C/S架构。RFC…

自学SAP是学习ECC版本还是S4版本?

很多人想学SAP&#xff0c;问我应该学ECC版本还是S4版本&#xff0c;我的建议如果你是自学的话&#xff0c;我个人建议使用ECC版本就行&#xff0c;因为这两个版本前台业务和后台配置的操作差异并不大&#xff0c;主要差异在于数据库的差异&#xff0c;前台业务操作和后台系统配…

OS复习笔记ch12-1

文件系统 概述 文件是大多数应用程序的核心要素&#xff0c;文件系统是操作系统对用户来说最重要的部分之一。 本章的主要内容见下图&#xff1a; 文件&#xff0c;大家耳熟能详的就是的docx、pdf、jpg、MP4等各种后缀文件&#xff0c;根据任务需要文件又分成了文本、图片、…

构建可维护的返利系统:最佳实践与常见问题

构建可维护的返利系统&#xff1a;最佳实践与常见问题 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01; 在当今竞争激烈的电商市场中&#xff0c;返利系统作为一…

mediasoup源码分析(七)transport传输

transport传输 一、Tansport 转发到Producer二、RtpStreamRecv 处理收到的包三、数据传输到Router&#xff0c;再分发到Consumertips 一、Tansport 转发到Producer Transport收到数据packet后&#xff0c;会解析出packet中所带的ssrc字段&#xff0c;然后基于ssrc找到该数据的…

超越YOLOv8,飞桨推出精度最高的实时检测器RT-DETR!

众所周知&#xff0c;实时目标检测( Real-Time Object Detection )一直由 YOLO 系列模型主导。 飞桨在去年 3 月份推出了高精度通用目标检测模型 PP-YOLOE &#xff0c;同年在 PP-YOLOE 的基础上提出了 PP-YOLOE 。后者在训练收敛速度、下游任务泛化能力以及高性能部署能力方面…

django使用uuid的坑,据说有外国公司已经为此损失了超1w刀

错误的代码 import uuid from django.db import models class MyModel(models.Model): id models.CharField(max_length32, primary_keyTrue, editableFalse, defaultstr(uuid.uuid4())) # 其他字段...上述代码错误的地方在于&#xff0c;defaultstr(uuid.uuid4())这部分…

我国目前常用的卫星影像星座有哪些(高分二号、高分七号、吉林一号、高景一号······)

​ 点击下方全系列课程学习 点击学习—>ArcGIS全系列实战视频教程——9个单一课程组合系列直播回放 点击学习——>遥感影像综合处理4大遥感软件ArcGISENVIErdaseCognition 中国目前的遥感卫星在数量、种类和应用领域上都取得了显著进展&#xff0c;覆盖了陆地、气象、海…

ViT:5 Knowledge Distillation

实时了解业内动态&#xff0c;论文是最好的桥梁&#xff0c;专栏精选论文重点解读热点论文&#xff0c;围绕着行业实践和工程量产。若在某个环节出现卡点&#xff0c;可以回到大模型必备腔调或者LLM背后的基础模型重新阅读。而最新科技&#xff08;Mamba,xLSTM,KAN&#xff09;…

第1章、数据库概览

1、数据管理的三个阶段&#xff08;利用计算机进行数据管理&#xff09; 人工管理阶段——>文件系统阶段——>数据库系统阶段 人工管理阶段的特点&#xff1a;①数据不能长期保存在计算机中、②数据与程序不具有独立性、③数据不共享。 文件系统阶段&#xff0c;文件系…

博弈论(Nim 游戏)

公平组合游戏ICG 若—个游戏满足: 由两名玩家交替行动;在游戏进程的任意时刻&#xff0c;可以执行的合法行动与轮到哪名玩家无关;不能行动的玩家判负; 则称该游戏为一个公平组合游戏。 NIM博弈属于公平组合游戏&#xff0c;但城建的棋类游戏&#xff0c;比如围棋&#xff0c;…