python保留两位小数: In [1]: a = 5.026 In [2]: b = 5.000 In [3]: round(a,2) Out[3]: 5.03 In [4]: round(b,2) Out[4]: 5.0 In [5]: '%.2f' % a Out[5]: '5.03' In [6]: '%.2f' % b Out[6]: '5.00' In [7]: float('%.2f' % a) Out[7]: 5.03 In [8]: float('%.2f' % b) Out[…
1. 最笨的办法 function get() { var s = 22.127456 + ""; var str = s.substring(0,s.indexOf(".") + 3); alert(str); } 2. 正则表达式效果不错 <script type="text/javascript"> onload = function(){ var a = "23.456322"; var aNew; var…
int_ip = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)]) ip_int = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])]) def get_ips(ip1,ip2): f=open('ips.txt','w') ip1_num = ip_int(ip1) ip2_num = ip_int(ip2) for i i…
参数: dict1, dict2 需求:如果dict1和dict2中有不同的key,那么返回这个(key, dict1[key]):如果dict1和dict2中有相同的key,但是value不同,返回这个(key, dict1[key]) 实现: def dict_different_data(first, second): """ get the different data bewtten two dicts objects return :result = first…
一.代码 import decimal decimal.getcontext().rounding = decimal.ROUND_HALF_UP def index(number): n = str(number*100) n = decimal.Decimal(n).__round__(1) n = n / decimal.Decimal("100") n = decimal.Decimal(str(n), decimal.getcontext()) return float(n.…
//------[获取两个日期中所有的月份中] function getMonthBetween(start,end){ var result = []; var s = start.split("-"); var e = end.split("-"); var min = new Date(); var max = new Date(); min.setFullYear(s[0],s[1]); max.setFullYear(e[0],e[1]); console…