Solved

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

Posted on 2014-01-21
3
1,313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

729 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