Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

615 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