阿旺的学习园地

—企业信息化、程序设计、软件应用及其它

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1、Print格式控制

  • Print 方法是按照字符比例进行打印,所以字符数与字符所占据的宽度固定的列的数目无关。例如,像 “W” 这样的宽字母占据的宽度超过一固定列宽,而像 "i" 这样的窄字母占据的宽度则较小。考虑到要使用比平均字符更宽的空间,表列一定要留有足够余地。另外,也可以使用固定间距的字体(像 Courier 字体)来确保每一字符均只占一列。

  • Tab(n) 用来将插入点定位在绝对列号上,这里,n 为列号。使用无参数的Tab将插入点定位在下一个打印区的起始位置。

  • 使用分号 (;) 直接将插入点定位在上一个被显示的字符之后。使用 (,)号 将插入点定位在下一个打印区得起始位置。

  • 每隔 14列开始一个打印区。每列的宽度是所有字符的平均宽度,字符的磅大小是对所选字体而言的。 

总结:通过设置等宽字体来消除误差,通过Tab(n)来控制对齐。

 

2、Format格式控制

  • 0 Digit placeholder:  Display a digit or a zero. If the expression has a digit in the position where the 0 appears in the format string, display it; otherwise, display a zero in that position. If the number has fewer digits than there are zeros (on either side of the decimal) in the format expression, display leading or trailing zeros. If the number has more digits to the right of the decimal separator than there are zeros to the right of the decimal separator in the format expression, round the number to as many decimal places as there are zeros. If the number has more digits to the left of the decimal separator than there are zeros to the left of the decimal separator in the format expression, display the extra digits without modification.
  • # Digit placeholder: Display a digit or nothing. If the expression has a digit in the position where the # appears in the format string, display it; otherwise, display nothing in that position. This symbol works like the 0 digit placeholder, except that leading and trailing zeros aren't displayed if the number has the same or fewer digits than there are # characters on either side of the decimal separator in the format expression.

总结:#号不补0,0号要补0

posted on 2011-12-05 15:37  阿旺  阅读(185)  评论(0编辑  收藏  举报