Yogesh Chauhan's Blog

What is the difference between float and double?

in Miscellaneous on February 23, 2020

Double

It has the double precision (15 decimal digits of precision). It usually occupies 64 bits in computer memory and represents fractional values. double occupies twice the memory occupied by float. 

Double precision may be chosen when the range or precision of single precision would be insufficient.

One of the first programming languages to provide single- and double-precision floating-point data types was Fortran.

Double takes 8 bytes for storage.

Float

It has single precision (7 decimal digits of precision). It usually occupies 32 bits in computer memory and represents a wide dynamic range of numeric values.

Float takes 4 bytes for storage.   

NOTE: Here's how the number of digits are calculated:

double has 52 mantissa bits + 1 hidden bit = 53 bits: (53*log(2))/log(10) = 15.95 digits

float has 23 mantissa bits + 1 hidden bit = 24 bits: (24*log(2))/log(10) = 7.22 digits


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How does @extend rule work in SCSS (Sass)?SCSSHow to add CurrencyPipe in TypeScript file in Angular 9 Project?AngularHow to add a Bar Chart in Angular App?AngularHow to link/add CSS file to HTML Document?CSSObservation of Human Behavior [Shopping Observation Example]MiscellaneousCheck whether a variable exists and not empty in PHPPHPHow to render Lists in React?ReactHow to get current timestamp in Swift 4 and 5?SwiftWhat is the difference between Loosely Typed Language and Strongly Typed Language?MiscellaneousWordPress: How to find all posts with a specific custom field value?WordPressThe SQL EXISTS OperatorSQL/MySQLLearn to Make a Simple Contact Us Form using PHP and PDO-MySQLPHP