Jump to content
  • 0

Double data type divide and reminder problem


Yelay12
 Share

Question

When Value of Type_DOUBLE  divide with any number i get zero reminder.

example, value = 43.0 divide by 2, get reminder is 0.

I want to get reminder 1  in script for above example. How to do it. Please help.Thank.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

[ @Yelay12 ]
---

Quote

When Value of Type_DOUBLE  divide with any number i get zero reminder.

First of all, what you want is modulo (%).

t = 43.0
gg.alert(tostring(t % 2))

---
You need to understand that "DOUBLE" is floating-point number, thus you might need to convert it first into integer/non-precision number using "tonumber()"

t = 43.2
gg.alert(tostring(tonumber(t) % 2))

---
Using "tonumber()" isn't really necessary, you can directly calculate it. Mine works:

gg.searchNumber(43, gg.TYPE_DOUBLE)
t = gg.getResults(1)
if t ~= nil then
gg.alert(tostring(t[1].value % 2))
end

---

Edited by kiynox
Link to comment
Share on other sites

  • 0
12 hours ago, kiynox said:

[ @Yelay12 ]
---

First of all, what you want is modulo (%).

t = 43.0
gg.alert(tostring(t % 2))

---
You need to understand that "DOUBLE" is floating-point number, thus you might need to convert it first into integer/non-precision number using "tonumber()"

t = 43.2
gg.alert(tostring(tonumber(t) % 2))

---
Using "tonumber()" isn't really necessary, you can directly calculate it. Mine works:

gg.searchNumber(43, gg.TYPE_DOUBLE)
t = gg.getResults(1)
if t ~= nil then
gg.alert(tostring(t[1].value % 2))
end

---

Thank bro for your replies.I will try this

Link to comment
Share on other sites

  • 0
12 hours ago, kiynox said:

[ @Yelay12 ]
---

First of all, what you want is modulo (%).

t = 43.0
gg.alert(tostring(t % 2))

---
You need to understand that "DOUBLE" is floating-point number, thus you might need to convert it first into integer/non-precision number using "tonumber()"

t = 43.2
gg.alert(tostring(tonumber(t) % 2))

---
Using "tonumber()" isn't really necessary, you can directly calculate it. Mine works:

gg.searchNumber(43, gg.TYPE_DOUBLE)
t = gg.getResults(1)
if t ~= nil then
gg.alert(tostring(t[1].value % 2))
end

---

@kiynox bro i have another question for alert. gg.alert() function is running when above if condition even is false.Why? Please.Thank

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.