krishna03

Number Formate

Apr 24th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. -(NSString *)stringFromNumber:(NSNumber *)number
  2. {
  3. NSLog(@"Input:---%@",number);
  4. NSNumberFormatter *numFormatter = [[[NSNumberFormatter alloc] init] autorelease];
  5. [numFormatter setMaximumFractionDigits:5];
  6. [numFormatter setMinimumFractionDigits:2];
  7. //[numFormatter setExponentSymbol:@"e"];
  8. NSString *str_num = [numFormatter stringFromNumber:number];
  9. NSLog(@"Output:---%@",str_num);
  10. return str_num;
  11. }
  12. in console i am getting like below
  13. Input:---2.940000057220459
  14. Output:---2.94
  15. Input:---2940.000057220459
  16. Output:---2940.00006
  17. Input:---2.940000057220459e-15
  18. Output:---.00
  19. Input:---2.940000057220459e-12
  20. Output:---.00
  21. Input:---2.940000057220459e-09
  22. Output:---.00
  23. Input:---2.940000057220459e-06
  24. Output:---.00
  25. Input:---0.002940000057220459
  26. Output:---.00294
  27. but i need like below for above inputs (order)
  28. ---2.94
  29. ---2940
  30. ---2.94e-15
  31. ---2.94e-12
  32. ---2.94e-6
  33. ---2.94e-9
  34. ---0.00294
Advertisement
Add Comment
Please, Sign In to add comment