question

rknoesel avatar image
rknoesel asked

SkProduct to PurchasePrice (int32) for ValidateIOSReceipt

On iOS, what is the correct way to convert the SkProduct.price (which is an NSDecimalNumber) to the int32 required by ValidateIOSReceipt? I assume simply multiplying by 100 is not going to be safe for all currencies.

One hax0ry way may be to format it to a string, remove any periods or commas, then parsing as integer? There must be a better way that I'm not aware of.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Actually, it's almost universally "multiply by 100". The list of currently circulating currencies is here: https://en.wikipedia.org/wiki/List_of_circulating_currencies. The way to get the currency to the correct value is to multiply by the "Number to basic", which is 100 for most practically every currency in circulation.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rknoesel avatar image rknoesel commented ·

Thanks Brendan, that's very helpful!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.