Russell Posted October 22, 2020 Posted October 22, 2020 Hello team!! I'm trying to ROUND a large decimal value obtained from DistanteToPoint: self.Object1:GetPosition():DistanceToPoint(self.Object2:GetPosition()) This is my line to obtain the distance that i show on screen with DrawText. But i don't know how encode or use Round() function to Round the value obtained from DistanceToPoint. I imagine it will be a simple line, but boy I am unable to code it. Many thanks!! Quote
IgorBgz90 Posted October 22, 2020 Posted October 22, 2020 Maybe so? Pseudocode: local distance=self.Object1:GetPosition():DistanceToPoint(self.Object2:GetPosition()) local distancei=math.floor(pos)--or Math:Round(pos) context:DrawText("Distance: "..tostring(distancei),2,26) String format: https://stackoverflow.com/questions/57950030/wow-rounding-to-two-decimal-places-in-lua Quote Here's an example using all the options: string.format("%x6.2f", 2.264) From left to right: % marks the start x tells it to pad right with xs 6 tells it the whole thing should be 5 characters long .2 tells it to round (or pad with 0s) to 2 decimal places So, the result would be xx2.26 1 Quote
Russell Posted October 22, 2020 Author Posted October 22, 2020 41 minutes ago, IgorBgz90 said: Maybe so? Pseudocode: Many thanks!! Finally works for me in my code: --Declaramos y Guardamos la distancia entre los 2 objetos que nos interesan. local Distancia= self.Objeto1:GetPosition():DistanceToPoint(self.Objeto2:GetPosition()) --Declaramos y redondeamos la distancia anterior para quitar los decimales. local DistanciaRedonda=Math:Round(Distancia) "Math:" was the command I needed to get "Round()" working on "Distancia" variable. Many thanks!! 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.