Floating Data Type – Basic to Advanced
Floating Data Type wo data type hota hai jisme hum decimal numbers store karte hain. Real-world me jaha bhi calculation, measurement, scientific values, engineering data ya financial values aati hain, waha float ka use hota hai. Is guide me hum float ka basic se lekar advanced concept tak sab kuch deep me samjhenge.
Floating Data Type Kya Hota Hai?
Floating (Float) Data Type decimal point wale numbers ko store karta hai. Jis number me decimal point hota hai wo floating number kehlata hai. Examples:
- 3.14
- 10.5
- -0.98
- 5.0
Ye fractional values store karta hai aur bahut chote se lekar bahut bade decimal numbers handle kar sakta hai.
Isse “Floating” Kyun Kehte Hain?
Isse Floating isliye bola jata hai kyunki iska decimal point fix nahi hota, balki value ke according “float” karta rehta hai. Examples:
- 3.1415
- 314.15
- 0.00031415
Decimal point number ke size ke hisab se shift hota rehta hai.
Float Ka Size Aur Range
Float aam taur par 4 bytes memory use karta hai.
Iska approx range hota hai: ±3.4 × 10⁻³⁸ se ±3.4 × 10³⁸ tak
Float Precision (Accuracy)
Float approx 6 se 7 digits tak accurate hota hai.
Example: Agar aap 3.14159265 store karte ho, to ye approx 3.141593 store karega.
Float Ki Internal Working (Advanced)
Float memory me 3 parts me store hota hai:
- Sign Bit – Number positive hai ya negative
- Exponent – Decimal point ka position
- Mantissa (Fraction) – Actual value
Is method ko Floating Point Representation kehte hain.
Float vs Integer – Comparison
| Feature | Integer | Float |
|---|---|---|
| Meaning | Poore number | Decimal wale number |
| Precision | Bilkul exact | Approx (6–7 digits) |
| Speed | Fast | Thoda slow |
| Use Case | Counting, age, quantity | Measurement, price, temperature |
Advantages of Float
- Decimal values support karta hai
- Memory kam use karta hai
- Calculation fast hoti hai
- Scientific aur engineering data ke liye best
Disadvantages of Float
- Accuracy limited hoti hai
- Rounding errors hoti hain
- Money calculation ke liye suitable nahi
JavaScript Example Programs
1. Basic Float Example
let price = 99.75; console.log(price);
2. Float Addition
let a = 5.5; let b = 2.3; console.log(a + b);
3. Float Multiplication
let result = 4.5 * 2.0; console.log(result);
4. Rounding a Float
let num = 3.141592; console.log(num.toFixed(3));
5. Rounding Error Example
let x = 0.1 + 0.2; console.log(x);
Final Summary
Float decimal number store karne ke liye use hota hai. Ye 4 bytes memory leta hai aur 6–7 digits tak precise hota hai. Measurements, scientific data ke liye best hai, lekin rounding errors ki wajah se money calculation me avoid kiya jata hai.
Comments
Post a Comment