sql二进制转十进制
This article aims to walk you through the SQL Decimal data type and its usage with various examples. We will also see how we can exercise this data type in SQL Server to help make SQL developer’s job easier.
本文旨在通过各种示例逐步介绍SQL Decimal数据类型及其用法。 我们还将看到如何在SQL Server中使用此数据类型,以帮助简化SQL开发人员的工作。
介绍 (Introduction)
Organizations deal with decimals on a day-to-day basis, and these decimal values can be seen everywhere in different sectors, be it in banks, the medical industry, biometrics, gas stations, financial reports, sports, and whatnot. Using whole numbers (by rounding decimal numbers) definitely makes one’s job easier but it often leads to inaccurate outputs, especially when we are dealing with a large number of values and crucial data. In such scenarios, it is ideal to use Sql Decimal data type in SQL Server to deliver correct results with perfect precision.
组织每天处理小数,这些十进制值可以在银行,医疗行业,生物识别,加油站,财务报告,体育等各种地方的不同部门中随处可见。 使用整数(通过四舍五入十进制数)无疑会使人的工作更轻松,但通常会导致输出不准确,尤其是当我们处理大量的值和关键数据时。 在这种情况下,理想的是在SQL Server中使用Sql Decimal数据类型来以完美的精度提供正确的结果。
It becomes very essential for SQL developers to choose the correct data types in the table structure while designing and modeling SQL databases. Let’s move forward and explore Decimal data type in SQL Server.
对于SQL开发人员来说,在设计和建模SQL数据库时选择表结构中的正确数据类型变得非常重要。 让我们继续前进,探索SQL Server中的Decimal数据类型。
前提条件 (Pre-requisite )
SQL Decimal data type is being used in SQL Server since forever. You can use any SQL Server version installed (starting 2000 or above) to understand this data type. We will be using SQL Server 2017 in this article for the demo purposes. If you don’t have any version installed on your system and wish to practice against the 2017 version, download it from here.
SQL Decimal数据类型从一开始就在SQL Server中使用。 您可以使用安装的任何SQL Server版本(从2000或更高版本开始)来了解此数据类型。 我们将在本文中使用SQL Server 2017进行演示。 如果您的系统上未安装任何版本,并希望针对2017版本进行练习,请从此处下载。
SQL Server中的十进制数据类型的基本语法 (The Basic syntax of Decimal data type in SQL Server)
Let’s take a look at the basic syntax of SQL Decimal Data type first. It is denoted as below:
首先让我们看一下SQL Decimal Data类型的基本语法。 表示如下:
- decimal [(p [,s])] 十进制[[p [,s])]
Where,
哪里,
- p stands for Precision, the total number of digits in the value, i.e. on both sides of the decimal point p代表精度,即值中的位数总数,即小数点的两侧
- s stands for Scale, number of digits after the decimal point s代表Scale&