Office中国论坛/Access中国论坛
标题: 怎么样才能实现五舍六入? [打印本页]
作者: vickygp 时间: 2007-7-16 19:44
标题: 怎么样才能实现五舍六入?
对某数值取小数点后两位,但是按5舍六入保留小数位,不知道能不能实现?谢谢了
作者: 一点通 时间: 2007-7-16 19:49
可以的
作者: vickygp 时间: 2007-7-16 21:29
<>麻烦告我一下怎么实现好吧</P>
作者: 一点通 时间: 2007-7-16 22:00
正常情况下可在格式中写入0.00
作者: jicheng 时间: 2007-7-16 22:09
<>Function sswr(x As Double, y As Double)</P>
<><br>sswr = Int(x * 10 ^ y + 0.4) / 10 ^ y</P>
<><br>End Function<br> </P>
<P>sswr(10.515,2)=10.51 </P>
<P>sswr(10.516,2)=10.52 </P>
[此贴子已经被作者于2007-7-16 14:12:15编辑过]
作者: hi-wzj 时间: 2007-7-16 22:14
<>Int(x * 10 ^ y + 0.4) / 10 ^ y</P>
<>同时要看负数是怎么舍和入的。</P>
作者: jicheng 时间: 2007-7-16 22:22
<>round同样有这种情况</P>
<>round(10.515,2)=10.52</P>
<>round(-10.515,2)=-10.51</P>
<P>否则的话先看<0的: 0-round(abs(-10.515),2)=-10.52</P>
作者: wang1950317 时间: 2007-7-16 23:12
< none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><B normal?><FONT face="Times New Roman">四舍六入的数字修约是与国际接轨的一种数据修约方法,国家有专门的标准以前是:数值修约规则 UDC 511.1/2 GB/T 8170-1987 不知近几年有没有新的标准。四舍六入关键是尾数为5的处理原则,下面摘录一段供参考:</P>
< align=center none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm center; TEXT-ALIGN:><B normal?> </B></P>
< none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm></FONT></B></P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><B normal?></B><B normal?>进舍规则<o:p></o:p></B></P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman">3.1 </FONT>拟舍弃数字的最左一位数字小于<FONT face="Times New Roman">5</FONT>时,则舍去,即保留的各位数字不变。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman"> </FONT>例<FONT face="Times New Roman">1</FONT>:将<FONT face="Times New Roman">12.1498</FONT>修约到一位小数,得<FONT face="Times New Roman">12.1</FONT>。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman"> </FONT>例<FONT face="Times New Roman">2</FONT>:将<FONT face="Times New Roman">12.1498</FONT>修约成两位有效位数,得<FONT face="Times New Roman">12</FONT>。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman">3.2 </FONT>拟舍弃数字的最左一位数字大于<FONT face="Times New Roman">5</FONT>;或者是<FONT face="Times New Roman">5</FONT>,而其后跟有并非全部为<FONT face="Times New Roman">0</FONT>的数字时,则进一,即保留的末位数字加<FONT face="Times New Roman">1</FONT>。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman"> </FONT>例<FONT face="Times New Roman">1</FONT>:将<FONT face="Times New Roman">1268</FONT>修约到“百”数位,得<FONT face="Times New Roman">13X10<SUP>2</SUP></FONT>(特定时可写为<FONT face="Times New Roman">1300</FONT>)。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman"> </FONT>例<FONT face="Times New Roman">2</FONT>:将<FONT face="Times New Roman">1268</FONT>修约成三位有效位数,得<FONT face="Times New Roman"> 127 X 10</FONT>(特定时可写为<FONT face="Times New Roman"> 1270</FONT>)。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman"> </FONT>例<FONT face="Times New Roman">3</FONT>:将<FONT face="Times New Roman">10.502</FONT>修约到个数位,得<FONT face="Times New Roman">11</FONT>。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman"> </FONT>注:本标准示例中,“特定时”<FONT face="Times New Roman"> </FONT>的涵义系指修约间隔或有效位数明确时。<o:p></o:p></P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm><FONT face="Times New Roman">3.3 </FONT>拟舍弃数字的最左一位数字为<FONT face="Times New Roman">5</FONT>,而右面无数字或皆为<FONT face="Times New Roman">0</FONT>时,若所保留的末位数字为奇数(<FONT face="Times New Roman">1</FONT>,<FONT face="Times New Roman">3</FONT>,<FONT face="Times New Roman">5</FONT>,<FONT face="Times New Roman">7</FONT>,<FONT face="Times New Roman">9</FONT>)则进一,为偶数(<FONT face="Times New Roman">2</FONT>,<FONT face="Times New Roman">4</FONT>,<FONT face="Times New Roman">6</FONT>,<FONT face="Times New Roman">8</FONT>,<FONT face="Times New Roman">0</FONT>)则舍弃。</P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm> </P>
<P none? mso-layout-grid-align: char; LAYOUT-GRID-MODE: 0pt; 0cm></P>
[此贴子已经被作者于2007-7-16 16:40:22编辑过]
作者: vickygp 时间: 2007-7-16 23:49
<>谢谢了。还有一个问题round函数在access里面怎么样取舍小数位呢?我计算round(7.285,2)=7.28,计算round(7.555,2)=7.56 怎么对第三位的5处理方法不一样呢?</P>
作者: wang1950317 时间: 2007-7-17 00:29
<>你看一下修约规则就明白了,以下按保留两位小数为例:</P>
<>例 7.2850000001 只要5后面有数字,则进位,结果7.29 </P>
<> 7.285000 5后面没有数字,则看5前一位,如是双数,则舍弃:结果7.28</P>
<P> 如5前面是单数,则进位,如7.275 结果为7.28</P>
[此贴子已经被作者于2007-7-16 16:29:54编辑过]
作者: jicheng 时间: 2007-7-17 00:34
<>round要四舍五入的话要加位数 round(x+0.0001)</P>
<>如round(7.285+0.00001,2)=7.28</P>
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) |
Powered by Discuz! X3.3 |