| 1 |
/*======================================================================*//** |
|---|
| 2 |
* |
|---|
| 3 |
* Utils for ActionScript 3.0 |
|---|
| 4 |
* |
|---|
| 5 |
* @author Copyright (c) 2007 Spark project. |
|---|
| 6 |
* @version 1.0.0 |
|---|
| 7 |
* |
|---|
| 8 |
* @see http://utils.libspark.org/ |
|---|
| 9 |
* @see http://www.libspark.org/ |
|---|
| 10 |
* |
|---|
| 11 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 12 |
* you may not use this file except in compliance with the License. |
|---|
| 13 |
* You may obtain a copy of the License at |
|---|
| 14 |
* |
|---|
| 15 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 16 |
* |
|---|
| 17 |
* Unless required by applicable law or agreed to in writing, software |
|---|
| 18 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 19 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|---|
| 20 |
* either express or implied. See the License for the specific language |
|---|
| 21 |
* governing permissions and limitations under the License. |
|---|
| 22 |
* |
|---|
| 23 |
*//*=======================================================================*/ |
|---|
| 24 |
package org.libspark.utils { |
|---|
| 25 |
import flash.errors.IllegalOperationError; |
|---|
| 26 |
|
|---|
| 27 |
/** |
|---|
| 28 |
* Number オブジェクトのためのユーティリティクラスです |
|---|
| 29 |
*/ |
|---|
| 30 |
public class NumberUtil { |
|---|
| 31 |
|
|---|
| 32 |
/*======================================================================*//** |
|---|
| 33 |
* @private |
|---|
| 34 |
*//*=======================================================================*/ |
|---|
| 35 |
public function NumberUtil() { |
|---|
| 36 |
throw new IllegalOperationError( "NumberUtil クラスはインスタンスを生成できません。" ); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
/*======================================================================*//** |
|---|
| 44 |
* 数値を 1000 桁ごとにカンマをつけて返します。 |
|---|
| 45 |
* @author taka:nium |
|---|
| 46 |
* @param number 変換したい数値です。 |
|---|
| 47 |
* @return 変換後の数値です。 |
|---|
| 48 |
*//*=======================================================================*/ |
|---|
| 49 |
static public function format( number:Number ):String { |
|---|
| 50 |
var words:Array = String( number ).split( "" ).reverse(); |
|---|
| 51 |
var results:Array = new Array(); |
|---|
| 52 |
var l:int = words.length; |
|---|
| 53 |
for ( var i:int = 0; i < l; i++ ) { |
|---|
| 54 |
results.push( words[i] ); |
|---|
| 55 |
if ( i % 3 == 2 ) { |
|---|
| 56 |
results.push( "," ); |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
return results.reverse().join( "" ); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
/*======================================================================*//** |
|---|
| 63 |
* 数値の桁数を 0 で揃えて返します。 |
|---|
| 64 |
* @author taka:nium |
|---|
| 65 |
* @param number 変換したい数値です。 |
|---|
| 66 |
* @param figure 揃えたい桁数です。 |
|---|
| 67 |
* @return 変換後の数値です。 |
|---|
| 68 |
*//*=======================================================================*/ |
|---|
| 69 |
static public function digit( number:Number, figure:int ):String { |
|---|
| 70 |
var str:String = String( number ); |
|---|
| 71 |
for ( var i:int = 0; i < figure; i++ ) { |
|---|
| 72 |
str = "0" + str; |
|---|
| 73 |
} |
|---|
| 74 |
return str.substr( str.length - figure, str.length ); |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|