English 中文(简体)
在将一些数字编为插图时,去除数字
原标题:Remove integer digits when formatting a number to a string

在将若干份标为示意图时,我可以限制在标注之后的特性,例如%.03f。 (点后显示3位数),但我如何删除点上的所有数字?

例如,我喜欢<代码>100.943到>>格式<943>

最佳回答

I think the only way for you to do that would be to remove the number before the decimal point using math, or string manipulation after the fact, like componentsSeparatedByString:@"."

A simple math way of removing it would be:

float initialValue = 100.943f;
int beforeDecimal = (int)initialValue;
float afterDecimal = initialValue - beforeDecimal;
问题回答

奥克·我猜想,我现在谈谈你的问题。

这里是你们将只摆脱扼杀的又一个解决办法。

例如:

NSString *floatAsString = @"123.456";
NSArray stringDivisions = [floatAsString componentsSeparatedByString:@"."];

Here what you will get in array is: 123 and 456 to separate string objects. Once you get two separate strings, you can play with them.

这是你们所需要的吗?

Simple way to do that, Here is an example,

首先,将你的胎体改为浮值。

浮动×=102.943;

in = x;

a. 浮动=x % y;

NSLog(@" x : %f y : %d ans : %f", x, y, ans);

因此,产出如下:

页: 1

y: 102

a 0.943000

希望是你们所需要的。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签