2018-10-10 18:03:03 -04:00
---
id: cf1391c1c11feddfaeb4bdef
2021-02-06 04:42:36 +00:00
title: Create Decimal Numbers with JavaScript
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/ca8GEuW'
forumTopicId: 16826
2021-01-13 03:31:00 +01:00
dashedName: create-decimal-numbers-with-javascript
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as < dfn > floating point< / dfn > numbers or < dfn > floats< / dfn > .
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
**Note**
Not all real numbers can accurately be represented in < dfn > floating point</ dfn > . This can lead to rounding errors. [Details Here ](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems ).
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Create a variable `myDecimal` and give it a decimal value with a fractional part (e.g. `5.7` ).
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`myDecimal` should be a number.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(typeof myDecimal === 'number');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`myDecimal` should have a decimal point
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(myDecimal % 1 != 0);
2018-10-10 18:03:03 -04:00
```
2021-01-13 03:31:00 +01:00
# --seed--
## --after-user-code--
```js
(function(){if(typeof myDecimal !== "undefined"){return myDecimal;}})();
```
## --seed-contents--
```js
var ourDecimal = 5.7;
// Only change code below this line
```
2020-12-16 00:37:30 -07:00
# --solutions--
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
```js
var myDecimal = 9.9;
```