从数字中删除数字 [英] Removing Digits from a Number

查看:53
本文介绍了从数字中删除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道是否有办法从数字中删除(修剪)后两位或前两位.我有数字 4131,我想把它分成 41 和 31,但在网上搜索后,我只找到了如何从字符串中删除字符,而不是数字.我尝试将我的数字转换为字符串,然后删除字符,然后将其转换回数字,但我一直收到错误消息.

Does anybody know if there is a way of removing (trimming) the last two digits or first two digits from a number. I have the number 4131 and I want to separate that into 41 and 31, but after searching the Internet, I've only managed to find how to remove characters from a string, not a number. I tried converting my number to a string, then removing characters, and then converting it back to a number, but I keep receiving errors.

我相信我可以通过将数字除以 100 然后将数字四舍五入来获得前两位数字,但我不知道如何获得最后两位数字?

I believe I will be able to receive the first two digit by dividing the number by 100 and then rounding the number down, but I don't have an idea of how to get the last two digits?

有没有人知道用来实现我想要做的事情的函数,或者任何人都可以指出我正确的方向.

Does anybody know the function to use to achieve what I'm trying to do, or can anybody point me in the right direction.

推荐答案

试试这个:

var num = 1234

var first = num/100
var last = num%100

操场的输出正是您所需要的.

The playground's output is what you need.

​​

这篇关于从数字中删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆