moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

double rounding format not working on ios

Open DeltAagent00 opened this issue 4 years ago • 3 comments

<string name="byte_name_short">%.2f Byte</string>

for this string on iOS we got not rounded number

DeltAagent00 avatar May 06 '21 13:05 DeltAagent00

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.

dalewking avatar Feb 10 '22 18:02 dalewking

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 :)

Alex009 avatar Feb 11 '22 02:02 Alex009

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".

dalewking avatar Feb 11 '22 12:02 dalewking