Posts

Showing posts from November, 2026

C# Variables: float, double, and decimal

Image
  C# Variables: float , double , and decimal C# provides three common types for storing numbers with fractional values: float , double , and decimal . The correct choice depends on the required precision, memory usage, performance, and whether the value represents money or another human-facing quantity. The core difference The core difference is how they represent fractions : float and double are binary floating-point (base-2) — they approximate decimal fractions decimal is base-10 — it stores decimal fractions exactly float Size: 4 bytes Precision: Approximately 7 digits Range: Approximately ±3.4 × 10³⁸ Base: Binary Stores 0.1 exactly? No Suffix: f Use for: Graphics, games, and large arrays double Size: 8 bytes Precision: Approximately 15–17 digits Range: Approximately ±1.7 × 10³⁰⁸ Base: Binary Stores 0.1 exactly? No Suffix: Default; no suffix is required Use for: General mathematics and science decimal Size: 16 bytes Precision: 28–29 digits Range: Approxim...

Popular posts from this blog

Callback function in JavaScript

Using Generic in TypeScript about types in the Code

Bitwise Operators in C/C++