Javascript-蔬菜运算价格

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8 <script>
 9     //菜花了1.6 ,给了2块,问找零
10     var price=1.6;  //price是价格的意思
11     var money=2;
12     var change=money-price;
13     console.log("找零:"+change);
14     //通过四舍五入的方式找领的误差
15     console.log("找零:"+change.toFixed(2)); //toFixed(n)四舍五入 (n)则保留几位小数
16     //判断奇偶性
17     var num=prompt("情书一个数字:判断奇偶性") ; //string
18     var result=num%2;   //取余判断奇偶性
19     console.log("1.为奇数,2.为偶数:"+result);
20 </script>
21 </body>
22 </html>
原文地址:https://www.cnblogs.com/longly/p/6078978.html