Java decimal

Say, "1920 / 1080" is 1.777777777..., want the calculation to output '1.778'.

import java.text.DecimalFormat;

public class DecimalTest {
    private static DecimalFormat df = new DecimalFormat("0.000");
    public static void main(String[] args) {
        show((double) 1920 / 1080);
    }

    @SuppressWarnings("SameParameterValue")
    private static void show(Number number) {
        System.out.println("It is: '" + df.format(number) + "'.");
    }

}
It is: '1.778'.
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,136评论 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 14,240评论 3 20
  • 有所为而不为 无所为而为之 眼见为相 勿入思想 耳听为音 勿入思考 顺其自然 勿入心底 缘起性空 勿入尘埃 随缘恒...
    龙凤涅槃阅读 1,332评论 0 0
  • 突然明白,分手后拉黑删好友不给一点联系是多么善良的方式。 若你还未放下,可能真的会很想去联系他。 理智告诉你,不打...
    子衿cc阅读 1,241评论 0 0
  • 在最近期看了罗辑思维推荐的吴军博士的《智能时代》,接着延伸到朋友给的《暗时间》,脑中接收了一大堆信息,倍感杂乱...
    神仙二虎子阅读 3,561评论 1 3