- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Converting miles per gallon to kilometer per liter in JavaScript
Problem
We are required to write a JavaScript function that takes in a number in miles/gallon and return its equivalent km/litre.
Example
Following is the code −
const num = 25; const converter = (mpg) => { let LITRES_PER_GALLON = 4.54609188; let KILOMETERS_PER_MILE = 1.609344; const ratio = KILOMETERS_PER_MILE / LITRES_PER_GALLON; return Math.round(100 * mpg * ratio) / 100; }; console.log(converter(num));
Output
Following is the console output −
8.85
- Related Articles
- Converting km per hour to cm per second using JavaScript
- 1 Hz is equal to$(a)$. 1 vibration per minute$(b)$. 10 vibrations per minute$(c)$. 60 vibrations per minute$(d)$. 600 vibrations per minute
- Get max value per key in a JavaScript array
- Find the ratio of 50 km per hour to 30 m per second.
- The calorific value of a fuel is expressed in a unit called(a) kilojoule per litre (b) kilogram per millilitre(c) kilojoule per gram (d) kilojoule per kilogram
- How can I count visitors per page per day using MySQL?
- Differentiate between Earnings per share (EPS) and dilute Earnings per share (D-EPS).
- Converting array to set in JavaScript
- Converting degree to radian in JavaScript
- Converting ASCII to hexadecimal in JavaScript
- How to limit Database Resources per Session in Oracle?
- How many kilograms of tea, worth 300/- Per Kg should be mixed with 10 Kg of tea worth 240/- per kg to produce a mixture to cost 260/- per kg.
- Maximum of Column per Group in MySQL
- Converting string to MORSE code in JavaScript
- Converting whitespace string to url in JavaScript

Advertisements