Hi,
Can someone please tell me,
Is there any builtin function to convert decimal value to a fixed format?
e.g. 6 to 0006
10 to 0010
123 to 0123
4987 to 4987

You can do this with streams and manipulators:

#include <iomanip>
#include <iostream>

int main()
{
  std::cout << std::setw(4) << std::setfill('0') << 6 << '\n';
}

A string stream can be used to write the result to a string instead of stdout:

#include <iomanip>
#include <iostream>
#include <sstream>

int main()
{
  std::ostringstream oss;

  oss << std::setw(4) << std::setfill('0') << 6;
  std::cout << oss.str() << '\n';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.