⚙️ Why does 12.4338 + 10 become 22.433799999999998 in JavaScript? If you’ve ever noticed small inaccuracies in JavaScript math, such as unexpected decimal results, you’ve encountered a fundamental limitation of floating-point arithmetic — not a bug. JavaScript represents all numbers using the IEEE 754 double-precision (64-bit) standard. In this format, numbers are stored in binary, not decimal. However, many decimal fractions cannot be represented exactly in binary form — just like how 1/3 can’t be represented precisely in decimal (0.3333…). For example, the number 12.4338 cannot be stored exactly as-is. Internally, it becomes something like 12.433799999999998. So when you add 10, the result inherits this slight inaccuracy. These rounding artifacts are common in most programming languages that rely on floating-point math (JavaScript, Python, C#, etc.). If you are working with financial data or require exact decimal representation, it’s recommended to: - Use explicit rounding (.toFixed() or .toPrecision()), or - Use decimal arithmetic libraries such as decimal.js, big.js, or bignumber.js. Precision is rarely free — and understanding how numbers are stored is key to avoiding subtle data issues. #JavaScript #TypeScript #WebDevelopment #SoftwareEngineering #Programming #CleanCode #CodeQuality #TechEducation #FrontendDevelopment #FloatingPoint #IEEE754 #DeveloperTips #CodePrecision #LearnToCode #EngineeringExcellence
Why JavaScript's floating-point math can be inaccurate
More Relevant Posts
-
JavaScript has five key data types every developer should know: Number – for numeric data. BigInt – for very large numbers. String – for text manipulation. Boolean and Undefined – for logic and variable state. #JavaScript #WebDev #Programming
To view or add a comment, sign in
-
🔥 How Native Code Runs in the Browser: The Magic Behind WebAssembly Most developers still wonder: How do Rust, C/C++, Java, Go, Zig, or even Python run inside a browser — a place with no syscalls, no filesystem, no sockets, no processes, and no kernel? 🤯 Yet today we run: ⚡ Rust in Chrome ⚡ FFmpeg + ImageMagick fully client-side ⚡ Python, Ruby, Lua, Go via WASM ⚡ SQLite in a webpage ⚡ Game engines, physics engines & more So what’s the secret? 👉 WebAssembly isn’t an OS — it’s just a CPU. Browsers don’t give native APIs, so toolchains fake them using virtual syscalls, JS shims, and emulated OS layers. ✔ Virtual filesystems (MEMFS, IDBFS, OPFS) ✔ Threads via Web Workers + SharedArrayBuffer ✔ Networking via WebSockets/WebRTC ✔ Syscall virtualization through Emscripten, WASI & JS glue ✔ Stubbing + Polyfills for unsupported features In short: 💡 JavaScript becomes the kernel. 💡 WebAssembly gets a fake OS. 💡 Native code just runs, blissfully unaware it’s in a sandbox. This is how the modern web can execute “native” workloads—from video processing to ML inference—right in your browser. https://lnkd.in/gBFJnene #WebAssembly #WASM #Emscripten #WASI #RustLang #CProgramming #CPlusPlus #GoLang #Java #GraalVM #ZigLang #DevTools #WebDevelopment #Browsers #FrontendEngineering #SystemsProgramming #DeveloperExperience #PerformanceEngineering 🚀
To view or add a comment, sign in
-
-
For anyone that didn't already know this, but #JSON is your friend, especially when doing development testing on Postman... JSON is preferred because it optimizes readability, interoperability, and parsing speed. Key points: 1. Human-readable: Simple key–value structure with minimal syntax. Easy to debug and edit manually. 2. Language-independent: Supported natively or via libraries in nearly all programming languages, including C#, Python, and JavaScript. 3. Lightweight: No markup overhead like XML. Compact and efficient to transmit over networks. 4. Native web compatibility: Directly compatible with JavaScript objects, ideal for APIs and web applications. 5. Parsing efficiency: Modern parsers (e.g., System.Text.Json in .NET) handle JSON faster than XML or YAML. 6. Hierarchical structure: Supports nested objects and arrays naturally, fitting most data models. #architecture #designinnovation #computationaldesign #AECindustry
To view or add a comment, sign in
-
🔥 Developers, are you suffering from JavaScript Framework Fatigue? 🤯 Sometimes the answer to complexity isn't always more complexity. I met HTMX some time back, and its breath of fresh air in some usecases. HTMX: the anti-framework movement that's proving you can build modern, dynamic web applications without heavy client-side libraries like React, Angular, or Vue. HTMX is a breath of fresh air. It empowers you to perform advanced AJAX, CSS Transitions, and even WebSockets using nothing but simple HTML attributes. Your backend—whether Python, Go, or PHP—handles the logic, and HTMX handles the DOM manipulation. The result? ✅ Simplified tech stack ✅ Faster page loads ✅ Reduced development complexity ✅ A return to server-centric architecture This is the deliberate, minimalist path forward. If you’re tired of managing state and fighting toolchain sprawl, it’s time to look at the powerful simplicity of HTMX. I published a comprehensive guide covering everything you need to know about this revolutionary approach and why it belongs in your toolkit. https://lnkd.in/dVXGzJ25 #HTMX #WebDevelopment #JavaScriptFrameworks #Backend #Frontend #Minimalism #TechStack
To view or add a comment, sign in
-
✅ Day 60 - Advanced Flask: Making POST Requests with HTML Forms Today, I explored one of the most essential concepts in web development — handling POST requests in Flask! From creating HTML forms to processing user input securely, this lesson tied together frontend interaction and backend logic perfectly. Here’s what I learned: ✍️ How to create and structure HTML forms 🔁 Handling POST and GET requests in Flask 📨 Using smtplib to send real emails via a contact form 🧠 Understanding how user input flows from browser → server → response Building a functional contact form and connecting it with email sending logic really helped me see how real-world websites handle user communication. #100DaysOfCode #Flask #WebDevelopment #Python #LearningJourney
To view or add a comment, sign in
-
-
⚡ 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟭 — 𝗣𝗿𝗶𝗻𝘁 𝗘𝘃𝗲𝗻 𝗡𝘂𝗺𝗯𝗲𝗿𝘀 𝗕𝗲𝘁𝘄𝗲𝗲𝗻 𝟭 𝗮𝗻𝗱 𝗡 Today’s problem looks simple… but it’s the foundation of loops and logic — the building blocks of programming. 🧠 let N = 20; for (let i = 1; i <= N; i++) { if (i % 2 === 0) { console.log(i); } } ✅ 𝗢𝘂𝘁𝗽𝘂𝘁: 2, 4, 6, 8, ... 🧩 𝗪𝗵𝗮𝘁 𝘁𝗵𝗶𝘀 𝘁𝗲𝗮𝗰𝗵𝗲𝘀 𝘂𝘀: 𝟭.% (𝗺𝗼𝗱𝘂𝗹𝘂𝘀) 𝗵𝗲𝗹𝗽𝘀 𝗰𝗵𝗲𝗰𝗸 𝗱𝗶𝘃𝗶𝘀𝗶𝗯𝗶𝗹𝗶𝘁𝘆 — 𝘂𝘀𝗲𝗱 𝗵𝗲𝗿𝗲 𝘁𝗼 𝗱𝗲𝘁𝗲𝗰𝘁 𝗲𝘃𝗲𝗻 𝗻𝘂𝗺𝗯𝗲𝗿𝘀. 𝟮.=== 𝗶𝘀 𝘀𝘁𝗿𝗶𝗰𝘁 𝗲𝗾𝘂𝗮𝗹𝗶𝘁𝘆 (𝗻𝗼 𝘂𝗻𝗲𝘅𝗽𝗲𝗰𝘁𝗲𝗱 𝘁𝘆𝗽𝗲 𝗰𝗼𝗲𝗿𝗰𝗶𝗼𝗻). 𝟯.𝗟𝗼𝗼𝗽𝘀 + 𝗰𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝘀 = 𝘁𝗵𝗲 𝗳𝗼𝘂𝗻𝗱𝗮𝘁𝗶𝗼𝗻 𝗼𝗳 𝗮𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺𝗶𝗰 𝗹𝗼𝗴𝗶𝗰. 💪 👉 𝗣𝗿𝗼 𝘁𝗶𝗽:If you only need even numbers, you can loop with i += 2 starting at 2 to cut iterations in half. #javascript #learnwithzeba #codingjourney #frontend #webdevelopment #javascriptseries
To view or add a comment, sign in
-
-
💡 Exploratory Data Analysis on USA Housing Dataset 🇺🇸 Just uploaded my latest project on GitHub — an in-depth EDA of the USA Housing dataset! This project focuses on uncovering meaningful insights about housing prices using Python, pandas, NumPy, Matplotlib, and Seaborn. 🔍 Highlights: Data cleaning and preprocessing Correlation analysis between features like area, bedrooms, and price Visualizations to explore patterns and relationships Heatmaps and regression plots for better feature understanding 📊 This EDA helps identify the most influential factors affecting housing prices — a great foundation for future machine learning prediction models. 🧠 Tech Stack: Python | pandas | NumPy | Matplotlib | Seaborn | Jupyter Notebook 🔗 Check out the full notebook and visuals here: 👉 https://lnkd.in/girNxqgd #DataScience #EDA #MachineLearning #Python #DataAnalysis #GitHub #Visualization #USA #HousingMarket
To view or add a comment, sign in
-
💡 Did you know? In languages like Java or C++, changing a variable’s data type after it’s declared isn’t allowed. But in JavaScript, it’s totally possible — that’s what makes it so flexible and dynamic! ⚡ Example 👇 javascript let value = 10; // value is a number value = "Ten"; // now it's a string console.log(value); // Output: Ten This feature is called dynamic typing — one of JavaScript’s coolest traits! 👉 If you already knew this, drop a 💬 in the comments! #JavaScript #Programming #WebDevelopment #CodingFacts #LearnToCode #TechInsights
To view or add a comment, sign in
-
Learn to Use the Right Tool for the Right Problem! Building backends or web services? -> Use Go, C# (ASP.NET), or… TypeScript (🤢 I mean... JS is there on the web wether you like it or not) Doing machine learning or data processing? -> Go with Python — it’s built for that world. Need performance-critical speed and control? -> Rust is your best friend. Every language has its place. The trick is knowing when and where to use it. #software #web #programming #rust #csharp #aspnet #javascript #typescript #golang
To view or add a comment, sign in
-
Is JavaScript a Compiler or an Interpreter? It’s been a while since my last post, but I came across an interesting poll recently - it asked whether JavaScript is a compiler or an interpreter. Most people voted for interpreter, which makes sense… but it’s not completely true anymore. In the early days, JavaScript was interpreted, meaning it ran line by line without being compiled first. But that changed with modern engines like V8 (used in Chrome and Node.js). Today, JavaScript uses Just-in-Time (JIT) compilation, which means it starts by interpreting code, then compiles and optimizes the parts that run often - making it much faster over time. Here’s a quick breakdown of the main compilation types: Ahead-of-Time (AOT): Code is compiled before running (like C, C++, Rust). Just-in-Time (JIT): Code is compiled while running (like Java, C#, JavaScript). Interpreted: Code runs line by line without compilation (like Python, early JavaScript). So, is JavaScript interpreted or compiled? It’s actually both - it starts interpreted and becomes compiled as it runs. Pretty cool how much JavaScript has evolved, right? #javascript #compilation #aot #jit #interpreter #compiler
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
The .toFixed() saved me on many occasions.