V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
b821025551b
V2EX  ›  JavaScript

遇见个灵异事件

  •  
  •   b821025551b · 2015-08-04 18:23:11 +08:00 · 2444 次点击
    这是一个创建于 3181 天前的主题,其中的信息可能已经有所发展或是发生改变。

    eval(50).toFixed(2)>eval(100).toFixed(2)
    true
    被当成字符串处理了??

    6 条回复    2015-08-04 22:18:49 +08:00
    CosWind
        1
    CosWind  
       2015-08-04 18:38:28 +08:00   ❤️ 1
    toFixed返回的是string,可以用typeof看一下
    an168bang521
        2
    an168bang521  
       2015-08-04 19:19:49 +08:00   ❤️ 1
    var a=eval("50"),
    b= a.toFixed(2);
    c=parseInt(b);
    console.log(typeof a);//number
    console.log(typeof b);//string
    console.log(typeof c);//number
    console.log(eval(50).toFixed(2)>eval(100).toFixed(2));//true
    console.log(parseInt(eval(50).toFixed(2))>parseInt(eval(100).toFixed(2)));//false
    an168bang521
        3
    an168bang521  
       2015-08-04 19:22:21 +08:00   ❤️ 1
    b= a.toFixed(2), 后面是逗号,不是分号;楼主可以把一个一个的输出来看看;
    liking09
        4
    liking09  
       2015-08-04 22:18:11 +08:00 via Android
    test
    liking09
        5
    liking09  
       2015-08-04 22:18:29 +08:00 via Android
    teat
    liking09
        6
    liking09  
       2015-08-04 22:18:49 +08:00 via Android
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   894 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:20 · PVG 05:20 · LAX 14:20 · JFK 17:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.