Java Formatter Usage convertRGBDecToHex(String decimal)

Here you can find the source of convertRGBDecToHex(String decimal)

Description

Convert rgb dec to hex.

License

Open Source License

Parameter

Parameter Description
decimal the decimal

Return

the string

Declaration

public static String convertRGBDecToHex(String decimal) 

Method Source Code


//package com.java2s;
/*/*from  w  w w. ja v  a2s  . co  m*/
 * M2M ServiceFOTA ONM version 1.0
 *
 *  Copyright ? 2014 kt corp. All rights reserved.
 *
 *  This is a proprietary software of kt corp, and you may not use this file except in
 *  compliance with license agreement with kt corp. Any redistribution or use of this
 *  software, with or without modification shall be strictly prohibited without prior written
 *  approval of kt corp, and the copyright notice above does not evidence any actual or
 *  intended publication of such software.
 */

import java.util.Formatter;

public class Main {
    /**
     * Convert rgb dec to hex.
     * 
     * @param decimal the decimal
     * 
     * @return the string
     */
    public static String convertRGBDecToHex(String decimal) {
        String returnValue = null;
        Formatter formatter = null;

        formatter = new Formatter();
        returnValue = "#" + formatter
                .format("%02x%02x%02x", Integer.parseInt(decimal.substring(0, 3)),
                        Integer.parseInt(decimal.substring(3, 6)), Integer.parseInt(decimal.substring(6, 9)))
                .toString();
        return returnValue;
    }
}

Related

  1. byteArrayToHexString(byte[] bytes, int pos, int len)
  2. bytesToHexString(byte[] bytes)
  3. byteToHex(final byte[] bytes)
  4. byteToHexWithPrefix(final byte[] data)
  5. chatting(String fmt, Object... args)
  6. convertTimeToString(double d, String timeFormat)
  7. convertToMillions(double tmp)
  8. createHexadecimalString(byte[] data)
  9. digestToString(byte[] input)