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);
}.
如何格式化为带两位小数的货币?