Last Updated : Jan 1, 2023
Here, below we are going to show a couple of links in form of code in which we understand about the conversion.
One thing to note here that we have to convert string to float, but the float must have two decimals. Let us see the code.
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
- Here, as you see that we create one heading, paragraph and then again paragraph. There is no meaning to use these all here. You can directly use script tag.
- One thing to note that there must be one paragraph or say anything there in body to show text from script tag.
- Hence, two decimals are showed there at last. Whereas prasefloat is used to convert string to float.
- You can customize decimals by changing value in toFixed. And parse float will give error if it is unable to found number at first in string.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.
At last in conclusion, here we can say that with the help of this article we are able to convert string to float with two decimals.