C++

 
C++    
split函数:
#include   <iostream> 
#include   <vector> 
#include   <string> 
#include   <boost/algorithm/string.hpp> 

int   main()   
{ 
std::string     str   =   "1-56-89-52-41-56 "; 
std::vector <std::string>     result; 
boost::algorithm::split(result,   str,   boost::algorithm::is_any_of( "- ")); 

for(size_t   i   =   0;   i   <   result.size();   ++i) 
{ 
std::cout < <result[i] < <std::endl; 
} 
} 

运行结果: 
1 
56 
89 
52 
41 
56

此方法应该是返回接近参数的int或long或什么什么,API上说是通过把参数加上1/2,再将该结果舍入。那么,

int x = (int) Math.round(-24.8);

int y = (int) Math.round(24.45);

x=-25,y=24

这是咋算的啊?!

Orangelee/sa 回答:2 人气:6 解决时间:2009-12-06 00:18
满意答案
  好评率:100%
文档里说这个过程等价于
(long)Math.floor(a + 0.5d)
这就不难理解了吧
-24.8+0.5 = -24.3
floor( -24.3 ) = -25
24.45+0.5 = 24.95
floor( 24.95 ) = 24

floor( x ) 是取小于x的最大整数
-25是小于-24.3的最大整数,所以floor( -24.3 ) = -25
24是小于24.95的最大整数,所以floor( 24.95 ) = 24
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值