2018-09-30 22:01:58 +00:00
---
id: cf1391c1c11feddfaeb4bdef
title: Create Decimal Numbers with JavaScript
challengeType: 1
2019-02-14 17:24:02 +00:00
videoUrl: 'https://scrimba.com/c/ca8GEuW'
2019-07-31 18:32:23 +00:00
forumTopicId: 16826
2021-01-13 02:31:00 +00:00
dashedName: create-decimal-numbers-with-javascript
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +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-09-30 22:01:58 +00:00
2022-06-10 13:54:51 +00:00
**Note:** when you compute numbers, they are computed with finite precision. Operations using floating points may lead to different results than the desired outcome. If you are getting one of these results, open a topic on the [freeCodeCamp forum ](https://forum.freecodecamp.org/ ).
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --instructions--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
Create a variable `myDecimal` and give it a decimal value with a fractional part (e.g. `5.7` ).
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`myDecimal` should be a number.
2018-09-30 22:01:58 +00:00
```js
2020-11-27 18:02:05 +00:00
assert(typeof myDecimal === 'number');
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`myDecimal` should have a decimal point
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(myDecimal % 1 != 0);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --after-user-code--
2018-09-30 22:01:58 +00:00
```js
2018-10-20 18:02:47 +00:00
(function(){if(typeof myDecimal !== "undefined"){return myDecimal;}})();
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-10-25 16:55:58 +00:00
const ourDecimal = 5.7;
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
// Only change code below this line
2021-10-25 16:55:58 +00:00
2020-11-27 18:02:05 +00:00
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
2021-10-25 16:55:58 +00:00
const myDecimal = 9.9;
2018-09-30 22:01:58 +00:00
```