Home Common Problem 3.14 Is it float type or double type?

3.14 Is it float type or double type?

Jul 06, 2020 pm 03:55 PM
double float floating point number

3.14 is double type. Because the representation of 3.14 as a decimal in a computer is basically impossible to describe accurately and is generally just an approximation, so "3.14f" can be expressed as a float type, while 3.14 can only be expressed as a double type.

3.14 Is it float type or double type?

3.14 is double type

1. The double data type is similar to the single precision data type (float), but The accuracy is higher than float, and the memory space occupied during compilation varies according to different compilers.

Usually, single-precision floating point numbers occupy 4 bytes (32 bits) of memory space, and their numerical range It is -3.4E38~3.4E 38; the double precision type occupies 8 bytes (64 bits) of memory space, and its value range is -1.7E308~1.7E 308.

3.14 The representation of decimals in computers cannot be accurately described. It is generally just an approximation (except for special examples such as 0.5). This is why we cannot use floating point numbers to compare. ==, but uses the difference between two numbers to indicate that the two numbers are equal within a small range.

So 3.14f can be expressed as float type, and 3.14 can only be expressed as double type.

2. Declare a variable of double type: double puotient; initialize a variable of double type: puotient = 5.621456873; double puotinet = 5.62.

3. Float is generally 4 bytes, double is generally 8 bytes, and the range is larger than float.

3.14 Is it float type or double type?

Extended information:

1. In C language, double precision floating point (double) type, occupies 8 bytes (64-bit) memory space. The numerical range is -1.7E308~1.7E 308. Double precision is fully guaranteed to have 15 significant digits, and 16 bits are only guaranteed for some values. Single precision guarantees 7 significant digits, and some values ​​have 8 significant digits.

Floating point type is scientific notation in a narrow sense, double precision, that is, double. Double means two, two.

2. The C standard requires that the float type has a precision of 7 digits, and the representation range of the integer part must be at least -1.0E37 -- 1.0E 37. float is generally 32-bit.

The C standard stipulates that the minimum representation range of the integer part of the double type is the same as that of float, which is -1.0E37 to 1.0E37, but it requires the precision of the double type to be 15 to 16 bits. double is usually 64 bits. The control character for outputting double float type is %lf. When a variable is defined, it can be abbreviated as double.

3. Floating-point data type. The FLOAT data type is used to store single-precision floating-point numbers or double-precision floating-point numbers.

Floating point numbers use IEEE (Institute of Electrical and Electronics Engineers) format. Single-precision values ​​of floating-point type have 4 bytes, including a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa. The mantissa represents a number between 1.0 and 2.0.

Since the high-order bit of the mantissa is always 1, it is not stored as a number. This representation gives the float type a range between approximately -3.4E-38 and 3.4E-38.

For more related knowledge, please visit PHP Chinese website! !

The above is the detailed content of 3.14 Is it float type or double type?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
What is the maximum value of float? What is the maximum value of float? Oct 11, 2023 pm 05:54 PM

Maximum value of float: 1. In C language, the maximum value of float is 3.40282347e+38. According to the IEEE 754 standard, the maximum exponent of the float type is 127, and the number of digits of the mantissa is 23. In this way, the maximum floating point number is 3.40282347 e+38; 2. In the Java language, the maximum float value is 3.4028235E+38; 3. In the Python language, the maximum float value is 1.7976931348623157e+308.

How to convert string to decimal in php How to convert string to decimal in php Mar 22, 2023 pm 03:22 PM

PHP is a powerful programming language that is widely used in the field of web development. One of the very common situations is the need to convert a string to a decimal. This is very useful when doing data processing. In this article, we will explain how to convert string to decimal in PHP.

PHP floating point number rounding method PHP floating point number rounding method Mar 21, 2024 am 09:21 AM

This article will explain in detail the PHP floating point number rounding method. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP Floating Point Rounding Overview Floating point numbers are represented in computers as a decimal point followed by an exponent, however, they are often stored in approximations with a limited number of digits. When you need to round a floating point number to a specific precision, there are several ways to do it. Method 1. round() function The round() function rounds a floating point number to the nearest integer. It accepts floating point numbers and optional precision parameters. For example: $num=1.55;echoround($num);//Output: 2echoround($num,1)

Convert floating point number to string using strconv.FormatFloat function Convert floating point number to string using strconv.FormatFloat function Jul 25, 2023 am 11:45 AM

Use the strconv.FormatFloat function to convert floating point numbers into strings. In the Go language, we often need to convert floating point numbers into string types for output or storage needs. The strconv package is provided in the Go language, and the FormatFloat function in it can convert floating point numbers into string types. The FormatFloat function takes three parameters: f represents the floating point number to be converted, fmt represents the format, and prec represents the number of decimal places to retain. Among them, the f parameter

C++ program to convert double type variable to int type C++ program to convert double type variable to int type Aug 25, 2023 pm 08:25 PM

In C++, variables of type int can only hold positive or negative integer values; they cannot hold decimal values. There are float and double values ​​available for this purpose. The double data type was created to store decimals up to seven digits after the decimal point. Conversion of an integer to a double data type can be done automatically by the compiler (called an "implicit" conversion), or it can be explicitly requested by the programmer from the compiler (called an "explicit" conversion). In the following sections, we'll cover various conversion methods. Implicit conversions The compiler performs implicit type conversions automatically. To achieve this, two variables are required - one of floating point type and the other of integer type. When we simply assign a floating point value or variable to an integer variable, the compiler takes care of all the other things

Causes and avoidance strategies of PHP floating point calculation errors Causes and avoidance strategies of PHP floating point calculation errors Feb 27, 2024 pm 06:33 PM

As a popular server-side scripting language, PHP often encounters problems of loss of precision or calculation errors when performing floating-point calculations. These problems may affect the accuracy and stability of the program. This article will explore the causes of PHP floating point calculation errors, propose some avoidance strategies, and give specific code examples for reference. 1. Reasons for PHP floating-point calculation errors. In computers, floating-point numbers are represented in binary form, and binary cannot accurately represent all decimal decimals, which leads to the inaccuracy of floating-point numbers.

An in-depth explanation of PHP BCMath: Unleashing the potential of number operations An in-depth explanation of PHP BCMath: Unleashing the potential of number operations Feb 23, 2024 am 09:10 AM

:1. Introduction to BCMath BCMath is an extension library built into PHP, which is specially used to handle large integer and floating point number operations. It provides a wealth of functions to perform various mathematical operations such as addition, subtraction, multiplication, division, square, and square root, and supports digital representation in multiple bases. 2. Advantages of BCMath Compared with the arithmetic operators and functions natively provided by PHP, BCMath mainly has the following advantages: Higher precision: BCMath’s operation results can retain more significant digits, which is useful for calculations involving large numbers. scenes are particularly important. Wider range: BCMath can handle larger numbers than PHP's native data types, thus avoiding overflow or loss of precision issues. Richer features: BCMath provides

Round floating point numbers using Math.Round function in C# Round floating point numbers using Math.Round function in C# Nov 18, 2023 pm 02:17 PM

Using the Math.Round function in C# to round floating-point numbers requires specific code examples. In the C# programming language, sometimes we need to round floating-point numbers. At this time, we can use the Math.Round function to achieve this function. The Math.Round function is a built-in function in C# used for mathematical calculations. Its main function is to round the specified floating point number. The following is the common format of the Math.Round function: Math.Round(doub