使用“K”表示数字高于3的长度 [英] Using "K" on numbers higher than 3 length

查看:97
本文介绍了使用“K”表示数字高于3的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的最大值范围为0~9999,999。zh
我想转换后的数字将它缩短为K,


并且仅当int高于9999(10K)时,小于10K的数字将如下:9999,7000等。

 ///示例
int NumberWithoutKilo = 10000; // random int from 0~9999999,例如:10000
//转换后,将其存储到另一个int
int NumberWithKilo = 10;

任何想法?


谢谢。


解决方案

除以1000并将K放在最后。 (未经测试的代码)

 public static string ToKilo(int value)
{
if(value< 10000)
返回值的ToString();

return(value / 10000).ToString()+" K" ;;
}

当然为了使这个更有用,你应该考虑传递min值来转换。您还应该考虑如何显示某些值,因为12345应该显示为12.345K。


如果您感觉特别雄心勃勃,那么创建
自定义格式化程序
来做它然后你可以直接使用ToString


Hi,

I have a int in a range from 0 ~ 999,999 at a maximum.
I want to convert the numbers after the thousand to short it as K,

and only when the int is higher than 9999 (10K), so numbers less than 10K would be like: 9999, 7000, etc.

/// example
int NumberWithoutKilo = 10000; //random int from 0 ~ 999,999, for example: 10000
// after convert, store it into another int
int NumberWithKilo = 10;

Any Ideas?

Thanks.

解决方案

Divide by 1000 and put a K on the end. (untested code)

public static string ToKilo ( int value )
{
   if (value < 10000)
      return value.ToString();

   return (value / 10000).ToString() + "K";
}

Of course to make this more useful you should probably consider passing in the min value to convert. You should also consider how you'd want to display some values because 12345 should probably be displayed as 12.345K.

If you're feeling particularly ambitious then create a custom formatter to do it and then you can just use ToString directly.


这篇关于使用“K”表示数字高于3的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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