“变量转换”的版本间差异

来自Shiyin's note
跳到导航 跳到搜索
(以“==浮点数转成整数== *round:四舍五入 IDL>print,round(5.1),round(5.9) IDL> 5, 6 *ceil:向上进 IDL>print,round(5.1),round(5.9) IDL> 6, 6 *floor:截取...”为内容创建页面)
 
第12行: 第12行:
*整数范围很小(long),要转换大的整数,加上/L64
*整数范围很小(long),要转换大的整数,加上/L64
*[[astro_lib]]中的nint程序,可以代替round,而且
*[[astro_lib]]中的nint程序,可以代替round,而且
:*(1) if no absolute value exceeds 32767, then the array is returned as
:(1) if no absolute value exceeds 32767, then the array is returned as
as a type INTEGER instead of LONG
as a type INTEGER instead of LONG
:*(2) NINT will work on strings, e.g. print,nint(['3.4','-0.9']) will
:(2) NINT will work on strings, e.g. print,nint(['3.4','-0.9']) will
give [3,-1], whereas ROUND() gives an error message
give [3,-1], whereas ROUND() gives an error message

2012年9月19日 (三) 01:49的版本

浮点数转成整数

  • round:四舍五入
IDL>print,round(5.1),round(5.9)
IDL> 5, 6
  • ceil:向上进
IDL>print,round(5.1),round(5.9)
IDL> 6, 6
  • floor:截取整数
IDL>print,round(5.1),round(5.9)
IDL> 5, 5
  • 整数范围很小(long),要转换大的整数,加上/L64
  • astro_lib中的nint程序,可以代替round,而且
(1) if no absolute value exceeds 32767, then the array is returned as

as a type INTEGER instead of LONG

(2) NINT will work on strings, e.g. print,nint(['3.4','-0.9']) will

give [3,-1], whereas ROUND() gives an error message