Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate number of digits after floating point in iOS?

How can I calculate the number of digits after the floating point in iOS?

For example:

  • 3.105 should return 3
  • 3.0 should return 0
  • 2.2 should return 1

Update: Also we need to add the following example. As I want to know number of digits in the fraction part.

  • 1e-1 should return 1
like image 399
mohamede1945 Avatar asked Dec 03 '25 02:12

mohamede1945


1 Answers

Try this way:

NSString *enteredValue=@"99.1234";

NSArray *array=[enteredValue componentsSeparatedByString:@"."];
NSLog(@"->Count : %ld",[array[1] length]);
like image 196
Anoop Vaidya Avatar answered Dec 04 '25 15:12

Anoop Vaidya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!