将数字数字拆分为2个或更多部分的方法 [英] way to split numeric number into 2 or more parts
本文介绍了将数字数字拆分为2个或更多部分的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好编码员!
我想要一个小问题的帮助。想要将一个整数分成多个部分,例如Int Number = 645.I想把它分成两部分p1 = 600和p2 = 45.或
数= 3658.
p1 = 3000;
p2 = 600;
p3 = 58;
我怎样才能在C ++ / QT中得到它。
Hi coders!
i want assistance in one tiny problem. want to split one integer number into multiple parts e.g. Int Number = 645.I want to divide it into two parts p1= 600 and p2 = 45. OR
Number= 3658.
p1=3000;
p2=600;
p3= 58;
how i can get this in C++/QT.
推荐答案
模数运算符(%
)是你的朋友。你知道,例如:
The modulus operator (%
) is your friend. You know, for instance:
int i = 645;
int a = i % 100; // a is 45
int b = i - a; // b is 600
这篇关于将数字数字拆分为2个或更多部分的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文