Jump to content

[TUT] math methods


Recommended Posts

  • Vinyard changed the title to [TUT] math methods
  • 5 months later...
11 minutes ago, FernandoMTA said:

yes actually we can use some math methods in this, here I will show an example
 

-- The function rounds up a number and then truncates the decimal places.
function roundUpAndTruncate(number)
    -- Round number up
    local roundedNumber = math.ceil(number)
    
    -- The whole number (before truncating the decimal places)
    local integerPart = math.floor(roundedNumber)
    
    return integerPart
end

-- For example
local number1 = 232.98266601563
local number2 = 232.49445450000
local number3 = 232.50000000000

local result1 = roundUpAndTruncate(number1)
local result2 = roundUpAndTruncate(number2)
local result3 = roundUpAndTruncate(number3)

print("Case 1 - Result: " .. result1)
print("Case 2 - Result: " .. result2)
print("Case 3 - Result: " .. result3)

 

Edited by Shady1
  • Thanks 1
Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...