Friday 15 February 2013

sdk - Lua number currency format -


In Lua, how can I format a number for 2 decimal places? I have a value example: 25.333 and I want to display it instead of 25.33. Sometimes it's like an integer 55 and I want it to display 55.00. It is meant to display currency values ​​I have tried the example formatting functions, and no one advised what advice I do not have. Jerry

Basically, you want something like this:

  rdahlgren @ deimos: pts / 1: 5 files 48Kb $ lua lua 5.2.0 Copyright (c) 1994-2011 Lua.org, PUC- Rio & gt; X = 25 & gt; Y = 25.3333 & gt; Print (string format ("% .2f", x)) 25.00 & gt; Print (string format ("% .2f", y)) 25.33 & gt;    

No comments:

Post a Comment