0

I am using etherscan api to get balance using the address. But I am getting a response in wei. After some research, I got some WEI to eth converter methods.
WEI to eth
But I don't know which method will suitable for me and how I will convert this in Objective -c?

Thanks in advance.

1

ether also designates a unit (of 1e18 or one quintillion Wei) of the currency

WEI is just a simple conversion of ETH.

1 ETH = 10**18 WEI = 1000000000000000000 WEI
1 WEI = 1/10**18 ETH = 1/1000000000000000000 ETH

So in the end, all you have to do is divide the value by 1**18.

  • So am I correct with this : float a = [[dictWalletData valueForKey:@"result"]floatValue] / 1000000000000000000; – Mihir Oza Feb 13 '18 at 10:02
  • Theoretically yes. Be aware though, that 10**18 is a number that does not fit into a float. You need to implement some method to store numbers that big or use a library. Alternatively you could process it completely with strings, if you do not need to do any math with the result afterwards. – Fabian Iwanecki Feb 13 '18 at 10:06
  • I thought the max value for a float in Objective-C is 340282346638528859811704183484516925440. Much bigger than 10**18. – smarx Feb 13 '18 at 10:13
  • You are right. Excuse my mistake. You will be able to handle the numbers in Objective-C – Fabian Iwanecki Feb 13 '18 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.