Celsius To Fahrenheit Converter Using JavaScript

Submitted by: 
Language: 
Visitors have accessed this post 190 times.

This is a simple tutorial that we are going to learn today. And it's called Celsius To Fahrenheit Converter Using JavaScript. If you want to do this manually. First, you have the method to convert the Celsius to Fahrenheit. You have to take time for solving.

But if you have this program, you don't need to do this manually to get the Celsius to Fahrenheit.

Kindly type a value in the box then it will automatically view the result.

JavaScript

This is the script to get the result of Celsius to Fahrenheit.

  1. <script type="text/javascript" src="angular.min.js"></script>
  2.  
  3. <script>
  4. var app = angular.module('celsiusTofahrenheit', []);
  5. app.filter('single_inDecimal', function($filter) {
  6. return function(input) {
  7. if (isNaN(input)) return input;
  8. return Math.round(input * 10) / 10;
  9. };
  10. });
  11. app.filter('setDecimal', function($filter) {
  12. return function(input, places) {
  13. if (isNaN(input)) return input;
  14. var factor = "1" + Array(+(places > 0 && places + 1)).join("0");
  15. return Math.round(input * factor) / factor;
  16. };
  17. });
  18. app.controller('Ctrl', function($scope) {
  19. $scope.val = 1.56;
  20. });
  21. </script>

HTML

This is the HTML code to input the user the value to convert and to see automatically the result.

  1. <h3>Celsius To Fahrenheit Converter</h3>
  2. <div ng-app="celsiusTofahrenheit">
  3. <p>Temperature in Celsius:</p>
  4. <hr />
  5. <input type="number" step="1" autofocus="autofocus" ng-model="code_fahrenheit" maxlength="5" size="3"/>
  6. <hr />
  7. <p>The temperature in Celsius is <b style="color:blue;"> {{ code_fahrenheit }}&deg;C </b> its equivalent to Fahrenheit is <b style="color:blue;"> {{ (code_fahrenheit * 9/5) + 32 | setDecimal:1}}&deg;F</b>.</p>
  8. </div>

So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.