第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何實現(xiàn) Math.round 以實現(xiàn) 3dp 輸出?

如何實現(xiàn) Math.round 以實現(xiàn) 3dp 輸出?

楊__羊羊 2021-08-19 17:39:09
public class Favorite {    public static void main(String[] arguments) {    String itemName = "Golden Beans";    double offerPrice = 314;    int sellPrice = 321;    double value = (sellPrice - offerPrice);    int cashStack = 500_000;    double percentageProfit = ((value / offerPrice) * 100);    System.out.println("Approx. Offer Price is " + offerPrice);    System.out.println("Approx. Sell Price is " + sellPrice);    System.out.println("The potential profit margin is " + value);    System.out.println("With a cash stack of " + cashStack + " we can buy " + cashStack / offerPrice + " " + itemName +"s");    System.out.println("The profit margin of " + itemName + " as a percentage is " + percentageProfit);    }}制作一個我決定買賣價格的小程序,它告訴我利潤率。完畢然后找出我可以用 500,000 購買多少件商品。完畢然后通過讓程序告訴我購買價格的利潤來使其更高級。完畢然后讓程序輸出到小數(shù)點后三位。(這就是我被卡住的地方?。?
查看完整描述

3 回答

?
狐的傳說

TA貢獻1804條經(jīng)驗 獲得超3個贊

首先閱讀文檔 - java docs:

System.out.printf("%.3f", res);

或十進制格式

System.out.println(new java.text.DecimalFormat("#.000").format(500.12321313));


查看完整回答
反對 回復(fù) 2021-08-19
?
至尊寶的傳說

TA貢獻1789條經(jīng)驗 獲得超10個贊

嘗試printf()而不是println()使用格式%.3f

System.out.printf("The profit margin of %s as a percentage is %.3f%n" itemName,percentageProfit);



查看完整回答
反對 回復(fù) 2021-08-19
  • 3 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號