1
我有一些產品的價格,試圖計算一些保證金,併發送給另一個代理的價格報價。但是,我想讓它更具可讀性,浮點數是有太多的algharisms。下面的代碼說明了這種情況:如何格式化Jason中的浮點數以僅顯示兩位小數?
products([["Banana",1], ["Apple",2], ["Pinapple",2.5]]).
margin(2).
//Submit proposal plan, sends to the initiator my product offers
+!sendProposals[source(X)] : products(List) <-
.length(List,LLenght);
?margin(Z);
-+listSize(0);
while(listSize(Sz) & Sz < LLenght)
{
.random(Y);
.nth(Sz,List,Item);
.nth(0,Item,Name);
.nth(1,Item,Price);
.print("Product(",Sz,"): ",Name," base price $",Price, " calculating...");
//.string.format("%.2f", Price); .format2decimals(Price,X)
.send(X,tell,newProposal(Name,Y*Z+Price));
-+listSize(Sz+1);
}.
如何格式化爲帶兩位小數的貨幣?