String to Int conversion

Hi all, basically i have a string value of 04 and when i convert it to an Int the value changes to 4. I require that first character as i define what the item type is. This may seem like a stupid question to post, however i do not know another way to convert a string to int without it removing the leading 0

Any help is appreciated (also below is an example of what i have)

But in convert to 4 successfully? you comments on nodes suggest that, it will print out 04 again since you connected print to “get field” so it gets 04 (or reuse, not sure how VM process pure nodes) all over again

Don’t think you can have an integer with a leading 0 without modifying the C++ standard output. So in blueprints I am not sure that is possible. Maybe there is a better way to take input from the user and define the item type without having leading zeros.

How would you think i could modify the standard output? if i could at all. I haven’t started learning c++ yet so its all new to me. The only other option would be to split the string and have a variable for the Type and for the Part itself.

The String gets the value 04 which then gets converted into 4 (int) i require the conversion to be 04 (int) the reason the print was there is to show that the string never changes, if i converted the new int to a string it will print out would be 4

Would you mind sharing some more detail? It seems like a homemade problem to be honest and there might be a better way of going about it.
How many values are possible? If you want to know whether the first digit is zero, you could check whether the number is smaller than 10. That, of course, assumes that you don’t get values greater than 100. Checking for 203 would need extra logic.

Oh, I see. You have a misunderstanding about what’s happening. An integer is a numerical value, a number, while a string literal isn’t. Every whole number has an infinite amount of implicit leading zeros. 4, 04, 004 and 000000000000000004 are the same number, because they have the same value.

If you insist on using a numerical representation for your items (rather than a strongly typed one, which I would suggest you do instead), using a vector will be way easier to manage.

If you insist on using a single number to represent it (for whatever reason), don’t use the “first” digit, but the least significant one. For example, if you have the number 1342, you’d use 2, rather than 1. It will be far easier for two reasons:

  1. Unlike words, our numbers grow from right to left, as opposed to left to right.
  2. You can check the value of that number with a simple operation: value % 10 (that’s value modulo 10)

Ah, i understand why that is a thing now, and the value will never change on the players side, this is why i had it as the first character, which also helped for the arrays (even though i could do as you suggested with it being the last number, i dont think it matters much) Below is how i solved the problem for getting the ID’s and Spawning the item (2 images).

Basically i have an external database which holds a value of a part for example 242 the first number is to define what type of part it is (0=head, 1=hilt 2=handle) then the number after is the actual part. i did it this way so that i could constantly add more parts for the player to create. However the problem lies with the head part type (0) in that if an integer has a 0 in front of a number UE4 removes it.

After some further thought if Nebula Games Inc is correct in saying that i cannot stop this in blueprints i think i am pretty sure when i receive the part value i am going to need to split up the type and the partid itself in string format and then convert it to an integer so that it keeps its formatting.

i do think that my further thought is going to be the best solution if there is no way to stop ue4 from doing this