Rahph

convert

Oct 20th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. This is free and unencumbered software released into the public domain.
  3.  
  4. Anyone is free to copy, modify, publish, use, compile, sell, or
  5. distribute this software, either in source code form or as a compiled
  6. binary, for any purpose, commercial or non-commercial, and by any
  7. means.
  8.  
  9. Read the full license on ( http://unlicense.org )
  10. Original code made by Rph
  11. ]]--
  12.  
  13. local api = {}
  14. function api.convert( nValue )
  15.     local unit = " J"
  16.     if nValue > 999 and nValue < 1000000 then
  17.         unit = " KJ"
  18.         return math.floor(nValue / 1000) .. unit
  19.     elseif nValue > 999999 and nValue < 1000000000 then
  20.         unit = " MJ"
  21.         return math.floor(nValue / 1000000) .. unit
  22.     elseif nValue > 999999999 then
  23.         unit = " GJ"
  24.         return math.floor(nValue / 1000000000) .. unit
  25.     else
  26.         return nValue .. unit
  27.     end
  28.     return "Wot"
  29. end
  30. return api
Advertisement
Add Comment
Please, Sign In to add comment