V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yoo
V2EX  ›  问与答

Python中如何获得小数点位数?

  •  
  •   yoo · Oct 23, 2012 · 10268 views
    This topic created in 4944 days ago, the information mentioned may be changed or developed.
    如题,计算会得到多个结果,如何获取结果的小数点后的位数,将符合位数的结果输出。
    3 replies    1970-01-01 08:00:00 +08:00
    liuxurong
        1
    liuxurong  
       Oct 23, 2012
    round?
    paloalto
        2
    paloalto  
       Oct 23, 2012
    循环得到的结果,然后用正则匹配出符合你要求位数的那个结果。

    ps:round是用来限定位数的吧?

    round(1/3.0,2)
    --->0.33000000002
    print round(1/3.0,2)
    --->0.33
    rexren
        3
    rexren  
       Oct 24, 2012
    用round限定你需要的位数 然后和原数作比较。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3834 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 05:01 · PVG 13:01 · LAX 22:01 · JFK 01:01
    ♥ Do have faith in what you're doing.