Hi guys, I have a string interpolation in my softw...
# announcements
p
Hi guys, I have a string interpolation in my software and I have this situation below happening:
Copy code
val intValue: Int = 2498533
val foo = "<http://abc.com/$intValue|abc.com/$intValue>"
println("Foo: $foo") //Foo: <http://abc.com/٢٤٩٨٥٣٣|abc.com/٢٤٩٨٥٣٣>
But note that the interpolation is returning these non integer characters. Why this is happening? Shouldn’t it be
<http://abc.com/2498533|abc.com/2498533>
?
m
yup, should be that and I get "abc.com/2498533" locally too
p
I really don’t know what happened 😞
The issue happened in a Samsung A10
j
Looks like localization to me. Those look like characters for numerals (maybe arabic?)
image.png
p
why? Should kotlin localize literal strings?
m
An int is not a literal string though. Its doing automatic conversion from a number to its character representation on the ascii table for you. So if you really want to have the correcr numbers, you should format that int into a western style localised string before "printing"
j
It is localizing - the OS probably has its Locale set to something like UAE. You can override the behavior by passing an alternate Locale to String.format
p
@Michael de Kaste I am not printing it, instead I am using in a http request. @Jakub Pi That’s not the main question, it’s well known that the value has been localized, the main question is why it has been localized in a endpoint only used in a http request? It doesn’t make sense.
j
A String is a String. Doesn't matter if you print it, or use it in an http endpoint. I don't understand what you mean. Is the Locale different from what you expect? Does the string interpolation act differently in other parts of the application? Can you log the Locale before you do the interpolation? Has it been modified outside of your control? Are you running on an emulator (maybe you downloaded the wrong image?)