V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
djchurch007
V2EX  ›  PHP

PHP 是最好的语言

  •  
  •   djchurch007 · 2015-03-12 16:48:58 +08:00 · 4372 次点击
    这是一个创建于 3325 天前的主题,其中的信息可能已经有所发展或是发生改变。
    遇到一个小问题,一个人的力量太小,大家来看看,谁能解释一下原因

    ![source](http://djchurch007.b0.upaiyun.com/temp/source.png)

    ![result](http://djchurch007.b0.upaiyun.com/temp/result.png)
    31 条回复    2015-03-13 20:50:36 +08:00
    djchurch007
        1
    djchurch007  
    OP
       2015-03-12 16:50:43 +08:00
    djchurch007
        2
    djchurch007  
    OP
       2015-03-12 16:50:54 +08:00
    xfspace
        3
    xfspace  
       2015-03-12 16:52:01 +08:00
    提问的智慧呢...看到标题我就想B了...
    背景图不错.
    582033
        4
    582033  
       2015-03-12 16:54:50 +08:00
    恩 是啊,php最好了
    RemRain
        5
    RemRain  
       2015-03-12 16:58:55 +08:00
    #include <stdio.h>

    int main(int argc, char *argv[]) {
    printf("%.2f\n", 3.675);
    printf("%f\n", 350 * (1 + 5 / 100) / 100);
    printf("%.2f\n", 350 * (1 + 5 / 100) / 100);
    printf("%f\n", 3.500 * (1 + 5.00 / 100));
    printf("%.2f\n", 3.500 * (1 + 5.00 / 100));
    return 0;
    }


    output:
    3.67
    3.675000
    3.67
    3.675000
    3.68
    RemRain
        6
    RemRain  
       2015-03-12 16:59:25 +08:00
    #!/usr/bin/perl
    printf("%.2f\n", 3.675);
    printf("%f\n", 350 * (1 + 5 / 100) / 100);
    printf("%.2f\n", 350 * (1 + 5 / 100) / 100);
    printf("%f\n", 3.500 * (1 + 5.00 / 100));
    printf("%.2f\n", 3.500 * (1 + 5.00 / 100));


    output:
    3.67
    3.675000
    3.67
    3.675000
    3.68
    djchurch007
        7
    djchurch007  
    OP
       2015-03-12 16:59:46 +08:00
    @RemRain
    啥,c也这样么
    djchurch007
        8
    djchurch007  
    OP
       2015-03-12 17:00:39 +08:00
    @RemRain
    我去试试js,python和perl先,我以为是php的函数问题
    lijinma
        9
    lijinma  
       2015-03-12 17:03:46 +08:00
    楼主你看这个。

    lijinma
        10
    lijinma  
       2015-03-12 17:05:40 +08:00
    看这条。。

    b821025551b
        11
    b821025551b  
       2015-03-12 17:07:51 +08:00
    浮点数多次运算自然会这样,金融系统里关于钱的都不用小数表示,少见多怪了吧
    djchurch007
        12
    djchurch007  
    OP
       2015-03-12 17:14:35 +08:00
    @lijinma
    谢谢,差不多知道了原因了
    djchurch007
        13
    djchurch007  
    OP
       2015-03-12 17:14:50 +08:00
    @RemRain
    谢谢,差不多知道原因了
    djchurch007
        14
    djchurch007  
    OP
       2015-03-12 17:17:35 +08:00
    @b821025551b
    从严谨的角度来说,得先排除是否是自带函数的问题>_<,php果然是最好的语言
    djchurch007
        15
    djchurch007  
    OP
       2015-03-12 17:32:05 +08:00
    @lijinma
    在你的基础上我重新更新了下

    djchurch007
        16
    djchurch007  
    OP
       2015-03-12 17:33:24 +08:00
    155
        17
    155  
       2015-03-12 17:36:19 +08:00
    用bc math.
    mcfog
        18
    mcfog  
       2015-03-12 18:12:20 +08:00
    PHP浮点数的一个常见问题的解答 >> http://www.laruence.com/2013/03/26/2884.html
    leemw
        19
    leemw  
       2015-03-12 19:21:22 +08:00
    少女时代为你解答。。
    invite
        20
    invite  
       2015-03-12 19:37:27 +08:00
    jamlee
        21
    jamlee  
       2015-03-12 20:24:47 +08:00
    @djchurch007 php在内部喜欢直接用c的函数
    falcon05
        22
    falcon05  
       2015-03-12 21:39:44 +08:00 via iPhone
    @lijinma
    哥们这个工具不错啊,是叫psy shell?
    orvice
        23
    orvice  
       2015-03-12 21:53:25 +08:00
    背景图是少女时代喵
    csuzhangxc
        24
    csuzhangxc  
       2015-03-12 22:01:57 +08:00
    @b821025551b 借贴问一下,金融系统里,钱一般怎么表示?谢谢
    lincanbin
        25
    lincanbin  
       2015-03-12 22:12:38 +08:00
    大学如果有《计算机导论》这门课应该知道IEEE 754。

    然后如果你数据精确度有要求,储存和运算过程可以用大整数模拟浮点数。
    b821025551b
        26
    b821025551b  
       2015-03-13 09:48:34 +08:00
    @csuzhangxc 钱的单位统一为分,要求更高的统一到厘;折扣一般用100000代表10折,各种业务操作完毕等到展示的时候再转换单位。
    yxzblue
        27
    yxzblue  
       2015-03-13 13:46:07 +08:00
    @xfspace 黑得漂亮
    MrYELiex
        28
    MrYELiex  
       2015-03-13 14:20:43 +08:00
    我只是来求背景的
    <img src="http://pic1.zhimg.com/137609aa92136bd8e0c6141c4896157c_b.jpg" height="300" width="400" title="hehe">img</img>
    <img src="http://pic3.zhimg.com/1d12c1a3779c075dfa78e8203f0e03aa_b.jpg" height="300" width="400" title="hehe">img</img>
    djchurch007
        29
    djchurch007  
    OP
       2015-03-13 15:02:52 +08:00
    @MrYELiex
    拿好,请叫我雷锋;
    Magician
        30
    Magician  
       2015-03-13 19:59:32 +08:00
    背景图片已抱走
    lijinma
        31
    lijinma  
       2015-03-13 20:50:36 +08:00
    @falcon05 对的,你搜一下哈
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5426 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:40 · PVG 14:40 · LAX 23:40 · JFK 02:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.