JavaScript Numbers — தமிழ்

</>Coding Tamilan.← JavaScript course

JavaScript · Lesson 16 / 32 · தமிழ்

JavaScript Numbers

கருத்தைப் புரிந்துகொள்ளுங்கள். Code-ஐ மாற்றி இயக்குங்கள். ஒரு சிறிய பயிற்சியால் கற்றதை உறுதி செய்யுங்கள்.

Detailed notesRunnable JavaScriptPractice + answer

மூலப் பாட விளக்கங்கள் தமிழில் உள்ளன. கூடுதல் concept, practice மற்றும் answer notes ஆங்கிலத்தில் உள்ளன.

01 / Understand

முக்கியக் கருத்து

JavaScript Number uses floating-point arithmetic. Formatting controls presentation; it does not make floating-point values exact. Use integer minor units when appropriate for simple money calculations.

Learning goal: Explain what the example does, predict its result, and change it to solve the practice task.

02 / Explore

விரிவான விளக்கங்கள்

JavaScript-ல Numbers

JavaScript-ல ஒரே ஒரு Number type இருக்கு — IEEE 754 double-precision floating-point standard. Integers மற்றும் floats ஒரே type.

Number Basics

JavaScript reference fragmentCODE
const integer = 42;
const float = 3.14;
const hex = 0xFF;          // 255
const binary = 0b1010;     // 10
const scientific = 1.5e6;  // 1500000

// Special values
console.log(Infinity);          // Infinity
console.log(NaN);               // Not a Number
console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991

Common Pitfalls

JavaScript reference fragmentCODE
// Floating point precision issue
console.log(0.1 + 0.2);         // 0.30000000000000004
console.log(0.1 + 0.2 === 0.3); // false!

// Fix with toFixed
console.log((0.1 + 0.2).toFixed(1)); // "0.3" (string!)
console.log(+(0.1 + 0.2).toFixed(1)); // 0.3 (number)

// NaN எதுவுமே equal இல்ல — தன்னோடே கூட
console.log(NaN === NaN);  // false
console.log(Number.isNaN(NaN)); // true

Number Methods

JavaScript reference fragmentCODE
const n = 3.14159;
n.toFixed(2);        // "3.14" (string)
n.toPrecision(4);    // "3.142" (string)

Number("42");        // 42
Number("");          // 0
Number("abc");       // NaN
parseInt("42px");    // 42
parseFloat("3.14kg"); // 3.14
03 / Read & predict

முழுமையான உதாரணம்

Run this complete index.js program in the JavaScript console editor below. The earlier reference fragments may need a browser page or other surrounding setup.

index.js · complete exampleCODE
const unitPaise = 1999;
const quantity = 3;
const rupees = (unitPaise * quantity) / 100;
console.log(rupees.toFixed(2));
console.log(typeof rupees.toFixed(2));
எதிர்பார்க்கும் முடிவைப் பாருங்கள்
59.97
string
04 / Experiment

மாற்றி இயக்கிப் பாருங்கள்

Load the example, change a value, predict the output, and run it again. Use the console output to check your reasoning.

Open editor ↗

Editor load ஆனதும் code-ஐ ஏற்றி Run அழுத்துங்கள்.

OneCompiler என்ற இலவச வெளிப்புற சேவை code-ஐ இயக்குகிறது. Run செய்யும் code அங்கு அனுப்பப்படும். தனிப்பட்ட தகவல்கள் அல்லது secret keys உள்ளிட வேண்டாம்.

05 / Your turn

சிறிய பயிற்சி

Practice challenge

Change quantity to 2 and format to two decimal places.

விடை மற்றும் விளக்கம்

The displayed result is "39.98". toFixed returns text.

தவிர்க்க வேண்டிய தவறு: 0.1 + 0.2 is not exactly 0.3 in binary floating point. Do not use formatted strings as if they were numbers.

அடுத்த பாடத்திற்குத் தயாரா?

  • Explain the example in your own words.
  • Complete the challenge before revealing its answer.
  • Describe the common mistake and how to avoid it.
Coding Tamilan · Learn by doing.