JavaScript Tutorial/Dojo toolkit/sprintf
dojo string sprintf:%.3e
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.string.Builder");
dojo.require("dojox.string.sprintf");
function testIt() {
var s = dojox.string.sprintf("%.3e", 1234567890);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Integer sprintf
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.string.Builder");
dojo.require("dojox.string.sprintf");
function testIt() {
var s = dojox.string.sprintf("%04d-%02d-%02d", 12345, 12345, 12345);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Leave space in sprintf
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.string.Builder");
dojo.require("dojox.string.sprintf");
function testIt() {
var s = dojox.string.sprintf("[%10s]", "goat");
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>
Output as char
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/",
parseOnLoad : true
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
dojo.require("dojox.string.Builder");
dojo.require("dojox.string.sprintf");
function testIt() {
var s = dojox.string.sprintf("%c", 65);
alert(s)
}
</script>
</head>
<body onLoad="testIt();">
</body>
</html>