Jump to content

(Solved) Use ROUND with DISTANCETOPOINT...


Russell
 Share

Recommended Posts

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!!

Link to comment
Share on other sites

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

 

  • Thanks 1
Link to comment
Share on other sites

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!!

  • Like 1
Link to comment
Share on other sites

  • Russell changed the title to (Solved) Use ROUND with DISTANCETOPOINT...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...