Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The release of the iPhone 6 and the iPhone 6 Plus was extremely successful for Apple. However when iOS 8.1 was introduced, many iPhone users complained of quick battery drainage. Without even knowing, you may be unnecessarily using up your battery p…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now