2018-09-30 23:01:58 +01:00
---
id: cf1391c1c11feddfaeb4bdef
title: Create Decimal Numbers with JavaScript
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/ca8GEuW'
2019-07-31 11:32:23 -07:00
forumTopicId: 16826
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01: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-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01: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-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Create a variable `myDecimal` and give it a decimal value with a fractional part (e.g. `5.7` ).
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`myDecimal` should be a number.
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(typeof myDecimal === 'number');
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`myDecimal` should have a decimal point
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(myDecimal % 1 != 0);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --after-user-code--
2018-09-30 23:01:58 +01:00
```js
2018-10-20 21:02:47 +03:00
(function(){if(typeof myDecimal !== "undefined"){return myDecimal;}})();
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
var ourDecimal = 5.7;
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
// Only change code below this line
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
var myDecimal = 9.9;
```