Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to truncate and do not round 'double' number and convert to NSString for display

Posted on 2014-01-21
3
Medium Priority
?
1,546 Views
Last Modified: 2014-01-22
I have a double value as 1.095589665 for example. How can I convert this to a string for display and show 4 decimals without rounding? My result would be 1.0955.
0
Comment
Question by:dmalovich
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 2000 total points
ID: 39799318
        float number = 1.095589665;
        float x = (int)(number * 10000) / 10000.0;
        NSString *value = [NSString stringWithFormat:@"%.3f", x];
        NSLog(@"%@", value);

Open in new window


Output:
2014-01-22 10:32:09.288 round[16856:303] 1.095
0
 

Author Closing Comment

by:dmalovich
ID: 39799833
Perfect, thank you.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 39799837
You are welcome
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
How to take pictures with depth using iOS 10
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question