Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

separate thousand units
Started by jjrey95 Jun 24 2019 02:08 PM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jjrey95

[GLOBAL: userInfoPane.html]
jjrey95
  • Observer

  • 26 posts
  • Corona SDK

Good afternoon,
One question, with Corona is it possible to make the separation of thousands with the numbers? that is, I do not get $ 123456 but $ 123,456


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,585 posts
  • Corona SDK

comma_value:
https://roaminggamer.github.io/RGDocs/pages/SSK2/extensions/#string
 
https://github.com/roaminggamer/SSK2/raw/master/ssk2.zip
 
or just use the code directly:

-- ==
--    comma_value(val, n) - Converts a number to a comma separated string. (http://lua-users.org/wiki/FormattingNumbers)
--    val - The value to convert to comma separated string.
-- ==
function string.comma_value(amount)
  local formatted = amount
  while true do  
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end
print("$" .. string.comma_value(1234567))

prints
 

$1,234,567

Edited by roaminggamer, 24 June 2019 - 05:23 PM.

  • Alan PlantPot likes this


[topic_controls]
[/topic_controls]