`
Rod_johnson
  • 浏览: 74292 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

常用的数字转换

 
阅读更多

public final class NumberFormatter {

    //NGtodo 这里发现较多重复的代码,需要看看什么回事

 

 

 

    // ------------------------------ FIELDS ------------------------------

 

    private static final DecimalFormat OdotOO = new DecimalFormat("0.00");

    private static final DecimalFormat ZERO10 = new DecimalFormat("0000000000");

    private static final DecimalFormat Odot = new DecimalFormat("0.################");

    private static final DecimalFormat MMMcommaMMMdotOO = new DecimalFormat("###,###,###,##0.00");

    private static final DecimalFormat MMMcommaMMMdotO = new DecimalFormat("###,###,###,##0.0");

    private static final DecimalFormat MMMcommaMMM = new DecimalFormat("###,###,###,##0");

    private static final DecimalFormat ZERO12 = new DecimalFormat("000000000000");

    private static final char CURRENCY_SIGN = '¥'; // 人民币货币符号

 

 

 

    // -------------------------- STATIC METHODS --------------------------

 

    /**

     * 18.56=>"1856"

     *

     * @param amount double

     * @return String

     */

    public static String double2FullString(double amount) {

        DecimalFormat CURRENCYFORMATTER = new DecimalFormat("0.00");

        String str_amt = CURRENCYFORMATTER.format(amount);

        return str_amt.substring(0, str_amt.indexOf(".")) + str_amt.substring(str_amt.indexOf(".") + 1);

    }

 

    /**

     * 格式化长整型金额,前面补0,当长度参数少于值参数长度时,直接返回传入的值

 

     *

     * @param value  long 金额

     * @param length int 返回的格式化金额长度

     * @return String 格式化金额

 

     */

    public static String fillOInFrontOfLong(long value, int length) {

        long numlenght = String.valueOf(value).length();

        if (length <= numlenght) {

            return String.valueOf(value);

        }

        StringBuffer buf = new StringBuffer("");

        for (int i = 0; i < length - numlenght; i++) {

            buf.append("0");

        }

        buf.append(value);

        return buf.toString();

    }

 

    /**

     * 格式化金额输出

 

     *

     * @param money BigDecimal BigDecimal型金额

 

     * @return 格式化的金额, 格式为:###,###,###,##0.00

     */

    public static String number2MMMcommaMMMdotOO(BigDecimal money) {

        return MMMcommaMMMdotOO.format(money);

    }

 

    //add by ken

    public static String number2MMMcommaMMMdotOO(String money) {

        if( null == money || "".equals(money.trim()))

            return "";

        return MMMcommaMMMdotOO.format(new BigDecimal(money));

    }

 

    /**

     * 格式化金额输出

 

     *

     * @param number double double型金额

 

     * @return 格式化的金额, 格式为:###,###,###,##0.00

     */

    public static String number2MMMcommaMMMdotOO(double number) {

        return MMMcommaMMMdotOO.format(number);

    }

 

    /**

     * 格式化金额输出

 

     *

     * @param number double double型金额

 

     * @return 格式化的金额, 格式为:###,###,###,##0.00

     */

    public static String number2MMMcommaMMMdotO(double number) {

        return MMMcommaMMMdotO.format(number);

    }

 

    /**

     * 格式化金额输出

 

     *

     * @param money BigDecimal BigDecimal型金额

 

     * @return 格式化的金额, 格式为:###,###,###,##0.00

     */

    public static String number2MMMcommaMMM(BigDecimal money) {

        return MMMcommaMMM.format(money);

    }

 

    //add by ken

    public static String number2MMMcommaMMM(String money) {

        if(null == money || "".equals(money.trim()))

            return "";

        return MMMcommaMMM.format(new BigDecimal(money));

    }

 

    /**

     * 格式化金额输出

 

     *

     * @param number double double型金额

 

     * @return 格式化的金额, 格式为:###,###,###,##0.00

     */

    public static String number2MMMcommaMMM(double number) {

        return MMMcommaMMM.format(number);

    }

 

    /**

     * 格式化金额输出,自定义精确度,不四舍五入.

     *

     * @param money     double double型金额

 

     * @param precision int 精确度(小数点位数),<1时作0处理

     * @return String 按精确度格式化后的金额字符串,不四舍五入

 

     */

    public static String number2OdotCustom(double money, int precision) {

        StringBuffer buf = new StringBuffer("0");

        if (precision < 1) {

            precision = 0;

        } else {

            buf.append(".");

        }

        for (int i = 0; i < precision; i++) {

            buf.append("0");

        }

        DecimalFormat formatter = new DecimalFormat(buf.toString());

        return formatter.format(money);

    }

 

    /**

     * 格式化金额输出

 

     *

     * @param money BigDecimal BigDecimal金额

     * @return String 格式化的金额,格式为:0.00

     */

    public static String number2OdotOO(BigDecimal money) {

        return OdotOO.format(money);

    }

 

    public static String number2Odot(double number) {

        return Odot.format(number);

    }

 

    public static String number2OdotOO(double number) {

        return OdotOO.format(number);

    }

 

    /**

     * 转换小数为百分数,带精确度<br>

     * 例:<br>

     * number=0.02 digit=2 结果:02.00%<br>

     * number=0.02005 digit=2 结果:02.00%<br>

     *

     * @param number double 小数

     * @param digit  int 精确度(百分数的小数位数)

     * @return String 百分数

 

     */

    public static String number2Percent(double number, int digit) {

        StringTokenizer st = new StringTokenizer(number2OdotCustom(number, digit + 2), ".");

        StringBuffer inte = new StringBuffer(st.nextToken()); // 获取整数部分

        StringBuffer deci = new StringBuffer(st.nextToken()); // 获取小数部分

 

        while (deci.length() < (2 + digit)) { // 先保证小数部分位数达到2+精确度的长度,不足补0

            deci.append("0");

        }

        if ("0".equals(inte.toString().trim())) { // 整数部分为0,即考虑纯小数的情况

            return deci.substring(0, 2) + "." + deci.substring(2, 2 + digit) + "%"; // 小数部分前两位+"."+位置2开始,截到精确度长度+"%"

        } else {

            return inte + deci.substring(0, 2) + "." + deci.substring(2, 2 + digit) + "%";

        }

    }

 

    /**

     * 转换小数为百分数,带精确度<br>

     * 例:<br>

     * number=0.02 digit=2 结果:2.00%<br>

     * number=0.02005 digit=4 结果:2.005%<br>

     *

     * @param number double 小数

     * @param fill0  int 精确度(百分数的小数位数)

     * @return String 百分数

 

     */

    public static String number2PercentCustom(double number, int fill0) {

        StringTokenizer st = new StringTokenizer(number2OdotCustom(number, fill0 + 2), ".");

        StringBuffer inte = new StringBuffer(st.nextToken());

        StringBuffer deci = new StringBuffer(st.nextToken());

        if (deci.length() < (2 + fill0)) { // 小数部分长度<2+精确度的情况

            while (deci.length() < (2 + fill0)) { // 小数部分补0

                deci.append("0");

            }

            if ("0".equals(inte.toString().trim())) {// 纯小数的情况

                if ("0".equals(deci.substring(0, 1))) {// 小数第一位为0,输出的整数部分去0处理

                    return deci.substring(1, 2) + "." + deci.substring(2, 2 + fill0) + "%";

                } else {

                    return deci.substring(0, 2) + "." + deci.substring(2, 2 + fill0) + "%";

                }

            } else {

                return inte + deci.substring(0, 2) + "." + deci.substring(2, 2 + fill0) + "%";

            }

        } else {

            if ("0".equals(inte.toString().trim())) { // 纯小数的情况

                if ("0".equals(deci.substring(0, 1))) { // 小数第一位为0,输出的整数部分去0处理

                    return deci.substring(1, 2) + "." + deci.substring(2, deci.length()) + "%"; // 精确度以小数部分的位数为准

 

 

 

                } else {

                    return deci.substring(0, 2) + "." + deci.substring(2, deci.length()) + "%"; // 精确度以小数部分的位数为准

 

 

 

                }

            } else {

                return inte + deci.substring(0, 2) + "." + deci.substring(2, deci.length()) + "%"; // 精确度以小数部分的位数为准

 

 

 

            }

        }

    }

 

    /**

     * 按指定长度获取小数的数字,顺序从左到右,当指定长度大于小数作字符串的长度时,前面加上一个"¥"

     *

     * @param currency double 小数

     * @param digits   int 指定长度

     * @return char[] 格式化的字符数组

     */

    public static char[] number2YOdotCustom(double currency, int digits) {

        char[] result = new char[digits]; // 8 digits in receipt to print

        String s = number2OdotOO(currency); // 格式化金额为0.00只保留两位小数的格式

        int dotPos = s.indexOf(".");

        if (dotPos >= 0) // 存在小数点的情况

        {

            s = s.substring(0, dotPos) + s.substring(dotPos + 1); // 去除小数点,s=000

        }

        long ltmp = Long.parseLong(s);

        s = fillOInFrontOfLong(ltmp, digits); // 长度取精确度,判断前面是否用0补足长度,当digits>currency.length.

        boolean needMark = (s.charAt(0) == '0'); // 加入货币符的判断变量,进行了上面的补0则执行此步

 

 

 

        for (int i = 0; i < digits; i++) {

            if (needMark) // 当还没加入货币符的时候

 

 

 

            {

                if (s.charAt(i) == '0') // 去掉所有首0

                {

                    continue;

                } else {

                    if (i > 0) {

                        result[i - 1] = CURRENCY_SIGN;

                        needMark = false; // 加货币符判断置为false

                    }

                    result[i] = s.charAt(i); // 加入第一个字符

 

 

 

                }

            } else {

                result[i] = s.charAt(i); // 加入后续字符

            }

        }

        return result;

    }

 

    /**

     * 转换BigDecimal型金额为中文金额读数

     *

     * @param money BigDecimal BigDecimal型金额

 

     * @return String 中文表示的金额读数

 

     */

    public static final String toChineseCurrency(BigDecimal money) {

        // 暂时支持 123456789098 共12位整数的显示 (千亿级)

        StringBuffer RMB = new StringBuffer();

        String currency = number2OdotOO(money); // 总金额

 

 

 

        if (currency != null && !"".equals(currency.trim())) {

            currency = currency.trim();

            int intPartLength = 0, floatPartLength = 0; // 整数位及小数位长度

 

 

 

            int dotPosition = 0; // 小数点位置

 

 

 

            String intPart = "", floatPart = ""; // 整数部分及小数部分

 

 

 

            int multiZero = 0; // 连续的零的情况

 

 

 

            int maxDigitParts = 0; // 每四位存储段的数目

 

 

 

            boolean prefixZero = false; // 是否需要前导‘零’

 

 

 

            boolean suffixZero = false; // 是否需要后置‘零’

 

 

 

            String CHNCHAR = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿";

            String UNIT = "元角分整";

            int i, j = 0; // 循环计数器

 

 

 

            int tempnum = 0; // 临时存放数字

            dotPosition = currency.indexOf(".");

            if (dotPosition >= 0) { //有小数点

                intPart = currency.substring(0, dotPosition);

                floatPart = currency.substring(dotPosition + 1);

            } else {

                intPart = currency;

                floatPart = "";

            }

            intPartLength = intPart.length();

            floatPartLength = floatPart.length();

            // 处理整数部分

            if (intPartLength % 4 == 0) {

                maxDigitParts = intPartLength / 4;

            } else {

                maxDigitParts = intPartLength / 4 + 1;

            }

            String[] digitPart = new String[maxDigitParts];

            for (i = 0; i < maxDigitParts; i++) {

                digitPart[i] = "";

            }

            for (j = 0, i = intPartLength - 1; i >= 0; i--) {

                digitPart[j] += intPart.charAt(i);

                if ((intPartLength - i) % 4 == 0) {

                    j++;

                }

            }

            for (i = 0; i < maxDigitParts; i++) {

                StringBuffer tempBuf = new StringBuffer();

                for (j = 0; j < digitPart[i].length(); j++) {

                    tempnum = digitPart[i].charAt(j) - '0';

                    if (tempnum != 0) {

                        if (multiZero > 0) {

                            if (multiZero == j) { // 后续都是‘零’

 

 

 

                                if (i > 0) { // ‘万’位以上

                                    if (RMB.length() > 0 && RMB.charAt(0) != CHNCHAR.charAt(0)) {

                                        RMB.insert(0, CHNCHAR.charAt(0));

                                    }

                                    suffixZero = false;

                                }

                            } else {

                                tempBuf.insert(0, CHNCHAR.charAt(0));

                            }

                        }

                        multiZero = 0;

                        switch (j) {

                            case 1:

                                tempBuf.insert(0, CHNCHAR.charAt(10));

                                break;

                            case 2:

                                tempBuf.insert(0, CHNCHAR.charAt(11));

                                break;

                            case 3:

                                tempBuf.insert(0, CHNCHAR.charAt(12));

                        }

                        tempBuf.insert(0, CHNCHAR.charAt(tempnum));

                    } else {

                        multiZero++;

                        if (j == 0 && i > 0) {

                            suffixZero = true;

                        }

                        if (j == 3) {

                            prefixZero = true;

                        }

                    }

                }

                if (suffixZero && multiZero != 4) {

                    tempBuf.append(CHNCHAR.charAt(0)); // 修正后续‘零’

 

 

 

                    suffixZero = false;

                }

                if (prefixZero && multiZero != 4) {

                    tempBuf.insert(0, CHNCHAR.charAt(0)); // 修正前导‘零’

 

 

 

                    prefixZero = false;

                }

                if (multiZero != 4) {

                    switch (i) {

                        case 1: // 加‘万’字

                            RMB.insert(0, CHNCHAR.charAt(13));

                            break;

                        case 2: // 加‘亿’字

                            RMB.insert(0, CHNCHAR.charAt(14));

                            break;

                    }

                }

                multiZero = 0;

                prefixZero = false;

                suffixZero = false;

                RMB.insert(0, tempBuf.toString());

            }

            if (Long.parseLong(intPart) != 0) {

                RMB.append(UNIT.charAt(0)); // 加‘元’字

            }

            // 处理小数部分

            if (floatPartLength == 0 || "0".equals(floatPart) || "00".equals(floatPart)) {

                RMB.append(UNIT.charAt(3));

            } else {

                tempnum = floatPart.charAt(0) - '0';

                if (tempnum != 0 || RMB.length() > 0) {

                    RMB.append(CHNCHAR.charAt(tempnum));

                }

                if (tempnum != 0) {

                    RMB.append(UNIT.charAt(1)); // 加‘角’字

                }

                if (floatPartLength == 2) {

                    tempnum = floatPart.charAt(1) - '0';

                    if (tempnum != 0) {

                        RMB.append(CHNCHAR.charAt(tempnum));

                        RMB.append(UNIT.charAt(2)); // 加‘分’字

                    }

                }

            }

        }

        return RMB.toString();

    }

 

    /**

     * 转换double型金额为中文金额读数,12.00->壹拾贰元整 12.12-> 壹拾贰元壹角贰分

     *

     * @param money double double型金额

 

     * @return String 中文表示的金额读数

 

     */

    public static final String toChineseCurrency(double money) {

        // 暂时支持 123456789098 共12位整数的显示 (千亿级)

        StringBuffer RMB = new StringBuffer();

        boolean lowerZero = false;

        if (money < 0) {

            money = -money;

            lowerZero = true;

        }

        String currency = number2OdotOO(money); // 总金额

 

 

 

        if (currency != null && !"".equals(currency.trim())) {

            currency = currency.trim();

            int intPartLength = 0, floatPartLength = 0; // 整数位及小数位长度

 

 

 

            int dotPosition = 0; // 小数点位置

 

 

 

            String intPart = "", floatPart = ""; // 整数部分及小数部分

 

 

 

            int multiZero = 0; // 连续的零的情况

 

 

 

            int maxDigitParts = 0; // 每四位存储段的数目

 

 

 

            boolean prefixZero = false; // 是否需要前导‘零’

 

 

 

            boolean suffixZero = false; // 是否需要后置‘零’

 

 

 

            String CHNCHAR = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿";

            String UNIT = "元角分整";

            int i, j = 0; // 循环计数器

 

 

 

            int tempnum = 0; // 临时存放数字

            dotPosition = currency.indexOf(".");

            if (dotPosition >= 0) { //有小数点

                intPart = currency.substring(0, dotPosition);

                floatPart = currency.substring(dotPosition + 1);

            } else {

                intPart = currency;

                floatPart = "";

            }

            intPartLength = intPart.length();

            floatPartLength = floatPart.length();

            // 处理整数部分

            if (intPartLength % 4 == 0) {

                maxDigitParts = intPartLength / 4;

            } else {

                maxDigitParts = intPartLength / 4 + 1;

            }

            String[] digitPart = new String[maxDigitParts];

            for (i = 0; i < maxDigitParts; i++) {

                digitPart[i] = "";

            }

            for (j = 0, i = intPartLength - 1; i >= 0; i--) {

                digitPart[j] += intPart.charAt(i);

                if ((intPartLength - i) % 4 == 0) {

                    j++;

                }

            }

            for (i = 0; i < maxDigitParts; i++) {

                StringBuffer tempBuf = new StringBuffer();

                for (j = 0; j < digitPart[i].length(); j++) {

                    tempnum = digitPart[i].charAt(j) - '0';

                    if (tempnum != 0) {

                        if (multiZero > 0) {

                            if (multiZero == j) { // 后续都是‘零’

 

 

 

                                if (i > 0) { // ‘万’位以上

                                    if (RMB.length() > 0 && RMB.charAt(0) != CHNCHAR.charAt(0)) {

                                        RMB.insert(0, CHNCHAR.charAt(0));

                                    }

                                    suffixZero = false;

                                }

                            } else {

                                tempBuf.insert(0, CHNCHAR.charAt(0));

                            }

                        }

                        multiZero = 0;

                        switch (j) {

                            case 1:

                                tempBuf.insert(0, CHNCHAR.charAt(10));

                                break;

                            case 2:

                                tempBuf.insert(0, CHNCHAR.charAt(11));

                                break;

                            case 3:

                                tempBuf.insert(0, CHNCHAR.charAt(12));

                        }

                        tempBuf.insert(0, CHNCHAR.charAt(tempnum));

                    } else {

                        multiZero++;

                        if (j == 0 && i > 0) {

                            suffixZero = true;

                        }

                        if (j == 3) {

                            prefixZero = true;

                        }

                    }

                }

                if (suffixZero && multiZero != 4) {

                    tempBuf.append(CHNCHAR.charAt(0)); // 修正后续‘零’

 

 

 

                    suffixZero = false;

                }

                if (prefixZero && multiZero != 4) {

                    tempBuf.insert(0, CHNCHAR.charAt(0)); // 修正前导‘零’

 

 

 

                    prefixZero = false;

                }

                if (multiZero != 4) {

                    switch (i) {

                        case 1: // 加‘万’字

                            RMB.insert(0, CHNCHAR.charAt(13));

                            break;

                        case 2: // 加‘亿’字

                            RMB.insert(0, CHNCHAR.charAt(14));

                            break;

                    }

                }

                multiZero = 0;

                prefixZero = false;

                suffixZero = false;

                RMB.insert(0, tempBuf.toString());

            }

            if (Long.parseLong(intPart) != 0) {

                RMB.append(UNIT.charAt(0)); // 加‘元’字

            }

            // 处理小数部分

            if (floatPartLength == 0 || "0".equals(floatPart) || "00".equals(floatPart)) {

                RMB.append(UNIT.charAt(3));

            } else {

                tempnum = floatPart.charAt(0) - '0';

                if (tempnum != 0 || RMB.length() > 0) {

                    RMB.append(CHNCHAR.charAt(tempnum));

                }

                if (tempnum != 0) {

                    RMB.append(UNIT.charAt(1)); // 加‘角’字

                }

                if (floatPartLength == 2) {

                    tempnum = floatPart.charAt(1) - '0';

                    if (tempnum != 0) {

                        RMB.append(CHNCHAR.charAt(tempnum));

                        RMB.append(UNIT.charAt(2)); // 加‘分’字

                    }

                }

            }

        }

        if (lowerZero) {

            return "(负) " + RMB.toString();

        } else {

            return RMB.toString();

        }

    }

 

    public static char toChinese(int money) {

        char result = ' ';

        switch (money) {

            case 1:

                result = '壹';

                break;

            case 2:

                result = '贰';

                break;

            case 3:

                result = '叁';

                break;

            case 4:

                result = '肆';

                break;

            case 5:

                result = '伍';

                break;

            case 6:

                result = '陆';

                break;

            case 7:

                result = '柒';

                break;

            case 8:

                result = '捌';

                break;

            case 9:

                result = '玖';

                break;

            default:

                result = '零';

                break;

        }

        return result;

    }

 

    public static final String formatVerifyNoAmount(long amt) {

        return ZERO10.format(amt);

    }

 

    public static final String format12(double amt) {

        return ZERO12.format(amt);

    }

 

    public static void main(String[] args) {

        System.out.println(NumberFormatter.number2MMMcommaMMM(Double.parseDouble("11111111.99")));

    }

}

分享到:
评论

相关推荐

    罗马数字转换为大写汉字

    《罗马数字转换为大写汉字:CnumToHan类实现详解》 在计算机编程领域,尤其是在处理财务或会计相关的应用时,将数字转化为大写汉字是常见的需求。这不仅可以增加可读性,也有助于防止欺诈,因为汉字的书写比阿拉伯...

    C语言常用数字和字符串转换函数

    C语言常用数字和字符串转换函数,toi 字符串转换成整型数 atol 字符串转换成长整型数 atof 字符串转换成浮点型数 strtol 字符串转换成长整型数 strtoul 字符串转换成无符号长整型数 strtod 字符串转换成浮点数

    数字各种进制的转换

    - **十进制**(Base-10):我们日常生活中最常用的计数方式,包含0至9十个数字。 - **十六进制**(Base-16):除了0至9这十个数字外,还包括A至F六个字母,分别代表10至15。 2. **进制转换**:指不同进制数之间...

    C# - 阿拉伯数字金额转换为繁体数字金额

    阿拉伯数字系统是我们在日常生活中最常用的数字表示法,包括0、1、2、3、4、5、6、7、8、9这十个数字。而繁体数字则有自己独特的汉字对应,例如零(0)、壹(1)、贰(2)、叁(3)、肆(4)、伍(5)、陆(6)、柒...

    c语言字符串与数字转换函数

    C语言中提供了多种字符串与数字转换函数,以下是常用的几个函数: 1. atof() 函数:将字符串转换成浮点型数 atof() 函数的定义在stdlib.h头文件中,函数原型为:double atof(const char *nptr); atof() 函数会...

    数字逻辑基础 数字电路中常用的几种数制的表示方法及其转换规律

    在数字系统中,常见的编码方式有原码、反码、补码,用于表示有符号整数,其中补码是计算机中最常用的表示负数的方式。此外,还有格雷码(Gray Code),其相邻两数之间仅有一位不同,常用于编码和数据传输以减少错误...

    数字进制转换器v1.01

    《数字进制转换器v1.01:深入理解与应用》 数字进制转换是计算机科学中的基础知识,也是日常编程工作中不可或缺的一部分。本文将详细探讨数字进制转换器v1.01这一实用工具的功能及其背后的理论知识,旨在帮助用户更...

    数字进制转换器

    在计算机科学领域,数字进制转换是至关重要的基础概念,因为不同的进制系统用于表示和处理数据。进制转换器是一种工具,可以帮助我们方便地在十进制(Decimal)、十六进制(Hexadecimal)、八进制(Octal)和二进制...

    字符串和数字转换 C++ vs2008

    1. **`std::to_string()`**: 自C++11起,`std::to_string()`可以轻松地将数字转换为字符串。 ```cpp int num = 123; std::string str = std::to_string(num); ``` 2. **`std::stringstream`**: 使用`std::...

    一维字符数组大小写转换及字符与数字转换.pdf

    一维字符数组大小写转换及字符与数字转换.pdf 本资源主要讲解了 C 语言中的一维字符数组大小写转换和字符与数字转换的相关知识点。 知识点 1: 字符数组大小写转换 在 C 语言中,字符数组是一种常用的数据结构,...

    如何将数字型转换成货币型

    首先,需要创建一个`DecimalFormat`对象并指定适当的格式模式,然后使用`format`方法将数字转换为所需的格式: ```java String s = "22"; String f = new java.text.DecimalFormat("#,##0.00").format(Double....

    常用进制转换程序

    十六进制到二进制的转换可以看作是每个十六进制数字转换为四位二进制的过程。 该项目包含了一个名为"Example.sln"的文件,这通常是一个Visual Studio解决方案文件,意味着开发环境是Microsoft Visual Studio。解决...

    常用电平转换方案

    ### 常用电平转换方案详解 #### 一、引言 在电子系统设计中,电平转换是一项基本且重要的技术。随着不同设备之间接口电压的多样化,如何确保信号能够准确无误地在不同电平间进行转换成为了一个关键问题。本文将详细...

    pb 把数字转换为科学计数

    一、数字转换为科学计数法 在 PowerBuilder 中,我们可以使用字符串函数来实现数字到科学计数法的转换。一个常用的方法是使用 `ToString()` 函数,它可以将数值转换成字符串,并通过指定格式参数来控制输出的样式。...

    4种常用进制转换器

    进制转换器的运作原理是基于每种进制的基数,将一个进制的数字转换成其他进制的等值表示。例如,将十进制数25转换为二进制,我们需要知道十进制的25相当于二进制的11001。这个过程包括连续除以基数,记录余数,然后...

    Delphi常用类型转换

    11. Str 函数:将数字转换为格式化字符串(传统 Turbo Pascal 例程用于向后兼容)。 12. StrPas 函数:将零终止字符串转换为 Pascal 类型字符串,在 32 位 Delphi 中这种类型转换是自动进行的。 13. StrPCopy 函数:...

    oracle 如何判断一个字符串能否转换为数字?

    下面介绍两种常用的方法来判断一个字符串是否能够转换为数字: ##### 方法一:使用`TRANSLATE`函数 可以使用`TRANSLATE`函数将所有可能的数字字符(包括小数点、正负号和科学计数法中的“E”或“e”)替换为固定的...

    一个数字进制转换小工具

    4. DataConv.exe:这是编译后的可执行文件,用户可以直接运行进行数字转换操作。 5. DataConvDlg.h:这是头文件,定义了DataConvDlg类的接口,可能包含了用户界面控件和函数声明。 通过这些文件,我们可以推测这个...

    常用AD芯片 模数转换 芯片大全 型号选择

    AD 系列芯片是模数转换器的重要组成部分,它们用于将模拟信号转换为数字信号,以便于数字信号处理和计算。在电子系统中,AD 芯片广泛应用于数据采集、信号处理、自动控制等领域。下面是常用 AD 芯片模数转换器芯片...

Global site tag (gtag.js) - Google Analytics