ios - 将两位数的 NSInteger 拆分为两个 NSInteger

标签 ios nsinteger

我想弄清楚如何在 iOS 上获取两位数的 NSInteger(例如 11)并将其转换为 2 个独立的 NSInteger,每个看起来都像“1”。在 NSInteger 中它总是只有 2 位数字,不多不少,也没有小数。

最佳答案

您可以简单地使用整数/模运算

int tensDigit=originalNumber / 10;
int onesDigit=originalNumber % 10;

关于ios - 将两位数的 NSInteger 拆分为两个 NSInteger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30993847/

相关文章:

iphone - NSInteger 是一个 32 位整数吗

iOS 更改父 ViewController 的 Integer/NSNumber

objective-c - 将 View 的 NSInteger 属性设置为 NSInteger?

ios - SpriteKit SKAction 在删除和读取节点后不起作用

ios - css line-height 不适用于移动设备

ios - UitableView行选择和UIButton操作

ios - Google Maps SDK for iOS 在发布到 App Store 后崩溃

ios - 如何评估ios中的字符串方程

iphone - Interface Builder是否向UITableViewCell的contentView中添加元素?

ios - 生成一个随机的负 NSInteger