文章詳情頁
Java下數(shù)字類型的轉(zhuǎn)換方法
瀏覽:3日期:2024-06-20 10:57:17
內(nèi)容: 各種數(shù)字類型轉(zhuǎn)換成字符串型: String s = String.valueOf( value); // 其中 value 為任意一種數(shù)字類型。 字符串型轉(zhuǎn)換成各種數(shù)字類型: String s = '169'; byte b = Byte.parseByte( s ); short t = Short.parseShort( s ); int i = Integer.parseInt( s ); long l = Long.parseLong( s ); Float f = Float.parseFloat( s ); Double d = Double.parseDouble( s ); 數(shù)字類型與數(shù)字類對象之間的轉(zhuǎn)換: byte b = 169; Byte bo = new Byte( b ); b = bo.byteValue(); short t = 169; Short to = new Short( t ); t = to.shortValue(); int i = 169; Integer io = new Integer( i ); i = io.intValue(); long l = 169; Long lo = new Long( l ); l = lo.longValue(); float f = 169f; Float fo = new Float( f ); f = fo.floatValue(); double d = 169f; Double dObj = new Double( d ); d = dObj.doubleValue(); 實際應(yīng)用中還有可能會用到各數(shù)字類型與字節(jié)數(shù)組間的轉(zhuǎn)換, Java 沒有直接提供這樣的支持。這里我編寫了一個這樣的轉(zhuǎn)換工具。供大家參考使用:NumberTool.java 使用時請注意,數(shù)字類型轉(zhuǎn)換為字節(jié)數(shù)組時,存放的順序應(yīng)該是低位在前,高位在后。 Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd
標(biāo)簽:
Java
相關(guān)文章:
1. python鏈表類中獲取元素實例方法2. CSS代碼檢查工具stylelint的使用方法詳解3. IDEA設(shè)置編碼背景色的方法4. 詳解Vue中Axios封裝API接口的思路及方法5. Python astype(np.float)函數(shù)使用方法解析6. idea打開多個窗口的操作方法7. msxml3.dll 錯誤 800c0019 系統(tǒng)錯誤:-2146697191解決方法8. python GUI庫圖形界面開發(fā)之PyQt5 UI主線程與耗時線程分離詳細(xì)方法實例9. Django基于客戶端下載文件實現(xiàn)方法10. PHP 面向?qū)ο蟪绦蛟O(shè)計之類屬性與類常量實現(xiàn)方法分析
排行榜
