Skip to content

Instantly share code, notes, and snippets.

@act262
Last active March 11, 2017 15:44
Show Gist options
  • Save act262/831829ed17fe2ff5e3e823a806e3bdd2 to your computer and use it in GitHub Desktop.
Save act262/831829ed17fe2ff5e3e823a806e3bdd2 to your computer and use it in GitHub Desktop.
计算透明度百分比对应的十六进制值
/**
* 计算透明度百分比对应的十六进制值
*/
println "透明度百分比 -> 16进制"
for (int percent = 100; percent >= 0; percent--) {
int alpha = Math.round(255 * percent / 100d);
// println String.format("% 2d%% -> %s ", percent, Integer.toHexString(alpha).toUpperCase())
// 不带0x开头
// println String.format("%d%% -> %02X", percent, alpha)
// 带0x开头
println String.format("% 2d%% -> %#02X", percent, alpha)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment