Consider that we have a number like this.
const num = 123.1390;
Now, we need to format the above number according to specific decimal places like
toFixed() method formats a number and returns the string representation of a number. Be default the
toFixed() method removes the fractional part.
It also accepts the optional argument called
digits, which means we need to specify the number of digits after the decimal point.
Let’s see an example:
const num = 123.1390 // fractional part is removed console.log(num.toFixed()); // "123"
Now, you can see that our number is converted to a string representation. Because of this, we need to convert the string back to a number by adding
Formatting Number to Two Decimal places
console.log(+num.toFixed()); // 123
To format a number to two decimal places we need to pass
2 as an argument to the
const num = 123.1390 console.log(+num.toFixed(2)); // 123.13
Similarly, we can format a number according to our needs like this:
const num = 123.1390 // 1 decimal place console.log(+num.toFixed(1)); // 123.1 // 2 decimal places console.log(+num.toFixed(2)); // 123.13 // 3 decimal places console.log(+num.toFixed(3)); // 123.139
Improve your code with functional patterns like pure functions, compose & map/reduce/filter...plus advanced concepts like fusion, transducing and monads!
What you'll learn
For those who don't know, I'm a full stack web developer who has been in the industry for over 5 years now. There is a lot of things I have learned along the way and I'd like to share that knowledge with anyone wanting to learn!
like this video if you found it useful and would like to see more videos of the same content.
subscribe to my channel if you are trying to improve your abilities as a web developer, software engineer, or even if you are just learning to code.
Don't forget to turn on those bell notifications!
Python Programming Tutorials For Beginners
Hello and welcome to brand new series of wiredwiki. In this series i will teach you guys all you need to know about python. This series is designed for beginners but that doesn't means that i will not talk about the advanced stuff as well.
As you may all know by now that my approach of teaching is very simple and straightforward.In this series i will be talking about the all the things you need to know to jump start you python programming skills. This series is designed for noobs who are totally new to programming, so if you don't know any thing about
programming than this is the way to go guys Here is the links to all the videos that i will upload in this whole series.
In this video i will talk about all the basic introduction you need to know about python, which python version to choose, how to install python, how to get around with the interface, how to code your first program. Than we will talk about operators, expressions, numbers, strings, boo leans, lists, dictionaries, tuples and than inputs in python. With
Lots of exercises and more fun stuff, let's get started.
Download free Exercise files.
Who is the target audience?
First time Python programmers
Students and Teachers
IT pros who want to learn to code
Aspiring data scientists who want to add Python to their tool arsenal
Students should be comfortable working in the PC or Mac operating system
What will you learn
know basic programming concept and skill
build 6 text-based application using python
be able to learn other programming languages
be able to build sophisticated system using python in the future