PROBLEM 15
Easy

Currency Conversion

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#15

Given `amount` and exchange `rate` (units of target currency per one source unit), print the converted amount.

EXAMPLE

Example

Input
100 3.5
Output
350.0

LIMITS

Constraints

All numeric input values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Currency Conversion

JavaScript arithmetic works with numeric values stored in variables. A clear solution reads the needed values, computes the formula with `+`, `-`, `*`, `/` or `**`, and prints only the final result.

💡
NEED HELP? Hints
+

['Write the formula using named intermediate values if it contains more than one operation.', 'Verify the accumulator initial value and both loop boundaries; this is where off-by-one errors most often appear.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [amount, rate] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let result = amount * rate;
console.log(Number.isInteger(result) ? result.toFixed(1) : result);