Skip to content

Instantly share code, notes, and snippets.

@edinsoncs
Created July 5, 2016 04:31
Show Gist options
  • Select an option

  • Save edinsoncs/9c7ba59bf08e7197521e3f1da73f2169 to your computer and use it in GitHub Desktop.

Select an option

Save edinsoncs/9c7ba59bf08e7197521e3f1da73f2169 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var question = prompt("0 Parseint - 1 toFixed - 2 Parse Float")
var miNumber = convertNumber("50", question);
verify(miNumber);
function verify(scan) {
if (typeof scan) {
console.log(typeof scan + " " + scan);
}
}
/**
* convertNumber function return string to number
*/
function convertNumber(number, question) {
if (question == 0) {
//Convert Number One Form
return parseInt(number);
} else if (question == 1) {
return number.toFixed(0);
} else {
return parseFloat(number);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment