繁体   English   中英

如何显示星号的数量至最接近的千位?

[英]How to show number of asterisks to nearest thousand?

    bar1 = store1/1000;
    System.out.print("Store 1: ");
    for(int i = 1; i <= bar1; i++)
        System.out.print("*");

如何显示“ *”的数字四舍五入到最接近的千位。 现在,它只是四舍五入。

采用

bar1 = (store1+500)/1000;
    System.out.print("Store 1: ");
    for(int i = 1; i <= bar1; i++)
        System.out.print("*");

使用此代码:

    double store1 = 1095;
    long bar1 = Math.round(store1 / 1000);
    // int bar1 = store1/1000;
    System.out.print("Store 1: ");
    for (int i = 1; i <= bar1; i++)
        System.out.print("*");

或者如果stre 1是一个int并且您不能更改它,则可以使用:

    int store1 = 1095;
    long bar1 = Math.round(((double)store1) / 1000);
    // int bar1 = store1/1000;

它将把store1 / 1000的值四舍五入到最接近的1000。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM