473,388 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to format decimal numbers

Hi guyz,
could anyone please tell me how can I convert an integer variable like 1 to a string variable but with this format 00X where x is the number, I mean like let's say I want to have a string with fixed size (let's say 3) and I want to convert an int variable into that string but if the int variable is less than 100 I want it to have 0s before that so 1 -> 001 and 10->010

Regards,
May 1 '07 #1
2 1819
Banfa
9,065 Expert Mod 8TB
Look up sprintf and print format specifiers, for you purposes this will work

Expand|Select|Wrap|Line Numbers
  1. char string[11];
  2. int input = 10;
  3.  
  4. sprintf(string, "%03d", input);
  5.  
May 1 '07 #2
tnx alot :)
May 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
3
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
1
by: Nick | last post by:
Well, the project I am working on has now come to a screeching halt! I have been developing a program that heavily utilizes ADO.NET record sets. To generate reports, I convert the recordset to XML,...
1
by: Mike MacSween | last post by:
This looks like a bug to me. I have an expression on a report: =Format(Sum((**)*(/)),"0.00") Score is byte PercentOfGrade is double PropDegree is single ModuleCats is byte
1
by: Terencetrent | last post by:
I am trying to format a query expression drawn from a dialog box as percent. The original statement to get the value for the query is as follows: New%markup: !! The dialog box looks the...
2
by: Claus Haslauer | last post by:
Hi, I want to create a crosstab query that looks like this Date | Elevation 1 | Elevation 2 | ... ______________________________________________________________________ Date 1 | xx.y | xx.y...
5
by: Robin Tucker | last post by:
My database has a column for numeric data items. How can I use this number in the "format" command, such that for, say precision 2, I get numbers like 2011.01 or 2387.00 and for 4 I would get...
2
by: Carrie | last post by:
I have a number field with some numbers containing a decimal and some numbers with no decimal. In the code behind I put it into a decimal variable and to show this on a label I have the text of the...
7
by: pamela fluente | last post by:
My numericUpDowns show numbers in the format 1.500,56 (italy). Instead, I need *invariantly* that they show and accept the format 1,500.56, as in the USA. What's the right way to do that? I...
5
by: MyWaterloo | last post by:
I need to change the decimal value in one of my databases. Currently my company uses an ID system with nice whole numbers, i.e. no decimal numbers. Now my boss has this grand scheme to start using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.