diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java
index c40704dc7ac64ab00be24a7d4c7259cbf1ee3f7f..a18ee23a793b911520dc0b9359999da104b20040 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java
@@ -337,7 +337,11 @@ public abstract class Sprintf extends RBuiltinNode {
                 }
                 conversions[fi.numArg - 1] = fi.conversion;
             }
-            sb.append(fi.conversion);
+            char conversion = fi.conversion;
+            if (conversion == 'g' && args[fi.numArg - 1] instanceof Integer) {
+                conversion = 'd';
+            }
+            sb.append(conversion);
             i = fi.nextChar;
         }
 
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
index b69fe6363cea325c1fe0f2c2c43fd62d13deb516..ced94c6968126abbbbe8bcb3b99a580dbff36a3a 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
@@ -60049,6 +60049,10 @@ character(0)
 #{ sprintf("foo") }
 [1] "foo"
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_sprintf.testSprintf#
+#{ sprintf('plot_%02g', 3L) }
+[1] "plot_03"
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_sprintf.testSprintf#
 #{ sprintf(c("foo %f %d", "bar %f %d"), 7, 42L) }
 [1] "foo 7.000000 42" "bar 7.000000 42"
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sprintf.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sprintf.java
index 7a95cae93403ae46a6ad845bfd074cbbbba7db0d..d48f6c25f09d12b5d23eb290dfc1bf7642aafe83 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sprintf.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_sprintf.java
@@ -146,5 +146,6 @@ public class TestBuiltin_sprintf extends TestBase {
         assertEval("{ sprintf(c(\"foo %f %d\", \"bar %f %d\"), 7, 42L) }");
         assertEval("{ sprintf(c(\"foo %f %d\", \"bar %f %d\"), c(7,1), c(42L, 2L)) }");
         assertEval("{ sprintf(\"%.3g\", 1.234) }");
+        assertEval("{ sprintf('plot_%02g', 3L) }");
     }
 }