|
北京上课了讲述了PHP实现将科学计数法转换为原始数字字符串的方法,分享给大家供大家参考。
- <P><SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 15px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"></SPAN> <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">function NumToStr($num){<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> if (stripos($num,'e')===false) return $num;<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> $num = trim(preg_replace('/[=\'"]/','',$num,1),'"');//出现科学计数法,还原成字符串<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> $result = "";<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> while ($num > 0){<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> $v = $num - floor($num / 10)*10;<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> $num = floor($num / 10);<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> $result = $v . $result;<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> }</SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px"> return $result;<SPAN class=Apple-converted-space> </SPAN></SPAN>
- <SPAN style="WIDOWS: 1; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(245,252,238); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 14px/26px 微软雅黑, Verdana, Arial, Tahoma; WHITE-SPACE: normal; FLOAT: none; COLOR: rgb(51,51,51); WORD-SPACING: 0px; -webkit-text-stroke-width: 0px">}</SPAN></P>
复制代码
|
|