moko-resources
moko-resources copied to clipboard
double rounding format not working on ios
<string name="byte_name_short">%.2f Byte</string>
for this string on iOS we got not rounded number
We were investigating this for the opposite case where it is not outputting the trailing zeroes. So with a format string of "%1$.2f" and formatting with the value 9.0 we get the string "9" instead of the expected "9.00", which is what you get with Android.
I believe the issue is that on iOS all format types are converted to @ as in "%1$.2@" instead of %1$.2f", The issue is that with @ the rest of the format (e.g. the precision) is completely ignored. For @ it calls description or descriptionWithLocale on the object.
yes, now it's limitation of current implementation. https://github.com/icerockdev/moko-resources/blob/31103b4fa7bca2445487b9f9aafa9cc8085af3ca/resources/src/appleMain/kotlin/dev/icerock/moko/resources/desc/Utils.kt#L26
here you can see logic of formatting. for iOS all arguments from kotlin side will be just NSObjects. for NSObject we can't use %f, %d or something other - only %@.
if someone have ideas how fix this - please show :)
Without a fix you should at least document it in the readme and think about giving a build time warning if generating for iOS and it has these format types.
In terms of a fix would it not be possible to convert back to a primitive and pass that with the original format. The actual object you would have is an NSNumber object. So the logic would check is the object an NSNumber and the format type is f then get the double value from the NSNumber and pass that. There are weird cases with that though like "%1$f %1$s".