Solved

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

Posted on 2014-01-21
3
1,247 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating an installable image of an iPhone mobile app (an .ipa file) that beta testers could load onto their test devices. The process involved quite a few steps, but both Appcelerator and Diawi.org had decent …
     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON (https://github.com/SwiftyJSON/SwiftyJSON). If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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