# Arrays creating decimal place of a number from an array

Bugs will be moved here once resolved.

### » Wed Jan 25, 2017 9:09 pm

Problem Description
When taking a number out of an array and adding a prefix and placing the number into another array the resulting number will receive a decimal point.

The numbers i am working with are a 10 digit number with values representative of an id. the first 2 digits are the item and the following are the information. All the way up to 3699999999 works without issue and the results are correct. Around 3710100100 the numbers act oddly once they are put from one array to the other while adding the needed "item" prefix.

i have created a Capx with the findings and the steps to recreate the bug.

i am using this bit of code to add the information to the new array

Parameters for new array: Set at XY
X= ItemId
Y=0
Value="Item"&StartArray.At(ItemId)

some help on this would be fantastic as this is the final available item and i would like to not cut it from the game.

Attach a Capx
https://www.dropbox.com/s/9zple3tgc8wm5 ... .capx?dl=0

Description of Capx
This Capx is a recreation of the bug i have come across while working with arrays in a larger game.
All of the ItemIds work correctly except for the numbers in 3710100101 range.
The results and findings can be found and replicated in the capx file.

Steps to Reproduce Bug
• Step 1
Run the project in debug mode. (To make the arrays more visible and easily accessible press the eye button to watch the array data for each array and then use the watch Tab.)

• Step 2
Press either the "1" or the "2" button on the keyboard. ("1" will load the starting array with numbers that are problematic) ("2" Will load the starting array with numbers that work with no problems.

• Step 2
Press the "t" button on the keyboard to activate the function that transfers the information to the new array.

• Step 3
Check the values in the arrays and see the difference in the numbers. ("Start array" is the original values, "new array" is the ones with the "item" prefix)

• Step 4
The values can be changed in the Event sheet to test further if need be.

Observed Result
The numbers recieve deciamls
e.g.
3610100101 becomes "item3610100101" Which is correct
3710100100 becomes "item3710100099.9999995" which is incorrect
3710100101 becomes "item3710100101.0000005" incorrect

interestingly with the same string using the same code these numbers work fine;
3710100102,
3710100103,
3710100104,
3710100105,
3710100106,

but these following ones will also become decimals again.
3710100107 becomes "item3710100106.9999995" which is incorrect
3710100108 becomes "item3710100108.0000005" which is incorrect
3710100109 becomes "item3710100109.0000005" which is incorrect

Expected Result
All the numbers should directly transfer without adding mystery decimals.
3710100101 becomes "item3710100101"
3710100102 becomes "item3710100102"

Affected Browsers
• Chrome: (YES)
• FireFox: (YES)
• Internet Explorer: (not tested)

Operating System and Service Pack
Windows 10 Pro

Construct 2 Version ID
R239 (64bit)
B
4
S
1
Posts: 6
Reputation: 362

### » Wed Jan 25, 2017 11:16 pm

Perhaps the system expression round(x) would be of help in this situation at least until the bug (if it is a bug) is fixed?
B
62
S
20
G
56
Posts: 1,077
Reputation: 36,021

### » Wed Jan 25, 2017 11:24 pm

Thanks for the idea Burvey, but unfortunately I have tried with the system expressions like this, "Item"&floor(StartArray.At(ItemId)), "Item"&ceil(StartArray.At(ItemId)), and "Item"&round(StartArray.At(ItemId)). (Im assuming these are correct.)
Which i would have thought would eliminate the odd decimals that are occurring which it what leads me to believe this could be a bug
B
4
S
1
Posts: 6
Reputation: 362

### » Wed Jan 25, 2017 11:30 pm

Try it like this:

"Item"&StartArray.At(round(ItemId))
B
62
S
20
G
56
Posts: 1,077
Reputation: 36,021

### » Wed Jan 25, 2017 11:34 pm

Thank you again but alas im afraid still no luck the decimals are still coming through even with "Item"&StartArray.At(round(ItemId))
B
4
S
1
Posts: 6
Reputation: 362

### » Wed Jan 25, 2017 11:38 pm

I just ran your capx with the "Item"&StartArray.At(round(ItemId)) added and it looks like it fixed 3710100102 through 3710100106, but the others are still unfixed. Quite curious.
B
62
S
20
G
56
Posts: 1,077
Reputation: 36,021

### » Wed Jan 25, 2017 11:52 pm

Yeah its really bizarre that 3710100102 through 3710100106 are working correctly but the 0-1 and 7-9 acquire the decimal places
B
4
S
1
Posts: 6
Reputation: 362

### » Thu Jan 26, 2017 4:08 am

Sorry I can't verify this but maybe try:
"Item"&str(StartArray.At(ItemId))

str() converts a number to text differently than just using & as I recall. The reason was str(), which uses the js method to convert a number to text would often show long decimals like: 0.0999999999. So the default behavior with & would cause it to be prettier like 0.1. Anyways that's my rough reasoning.
B
95
S
33
G
128
Posts: 5,491
Reputation: 81,570

### » Thu Jan 26, 2017 4:41 am

I just tested @R0J0hound method and it works in your test capx! Try it in your real project and let us know how it goes.

"Item"&str(StartArray.At(ItemId))
B
62
S
20
G
56
Posts: 1,077
Reputation: 36,021

### » Thu Jan 26, 2017 9:46 am

Fantastic!!! I have had a look in the test Capx also and success!!!
I will add it into the code for my full project, Fingers Crossed.
il keep you up to date
B
4
S
1
Posts: 6
Reputation: 362

Next