473,791 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

data type for decimal number

which is the best format specifier(data type) if i have to work with
decimal number.

also please tell me the syntax for truncating a decimal number

please reply as soon as possible
Feb 16 '08
23 9803
Harald van D?k said:
On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
>Keith Thompson said:
>>Richard Heathfield <rj*@see.sig.in validwrites:
Actually, %x takes an int, not a hex. C doesn't have a hex type.

Actually, %x takes an unsigned int.

4.9.6.1 of C89:

d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );

Sure looks like int to me.

Interesting. C99 7.19.6.1p8:

o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Feb 18 '08 #11
On Feb 18, 11:46 am, Harald van D©¦k <true...@gmail. comwrote:
On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
Keith Thompson said:
Richard Heathfield <r...@see.sig.i nvalidwrites:
Actually, %x takes an int, not a hex. C doesn't have a hex type.
Actually, %x takes an unsigned int.
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.

Interesting. C99 7.19.6.1p8:

o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
ANSI/ISO 9899-1990
American National Standard for Programming Languages - C

7.9.6.1 The fprintf function

o, u, , x, X The unsigned int argument...
Feb 18 '08 #12
In article <7J************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?
My copies of C89 (which are BSI standard BS EN 29899:1993, and the BSI
copy of the ISO draft copied from ANSI distributed in 1989-90 for
comments), both specify unsigned int for o,u,x,X. A 1984 draft has
wording similar to yours.

-- Richard
--
:wq
Feb 18 '08 #13
On Feb 18, 12:22 pm, ymunt...@gmail. com wrote:
On Feb 18, 11:46 am, Harald van D©¦k <true...@gmail. comwrote:
On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
Keith Thompson said:
>Richard Heathfield <r...@see.sig.i nvalidwrites:
>>Actually, %x takes an int, not a hex. C doesn't have a hex type.
>Actually, %x takes an unsigned int.
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.
Interesting. C99 7.19.6.1p8:
o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]

ANSI/ISO 9899-1990
American National Standard for Programming Languages - C

7.9.6.1 The fprintf function

o, u, , x, X The unsigned int argument...
Another interesting thing:
http://www.lysator.liu.se/c/rat/d9.html#4-9-6-1
What the heck?
Feb 18 '08 #14
In article <7J************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Harald van D?k said:
>On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
>>Keith Thompson said:
Richard Heathfield <rj*@see.sig.in validwrites:
Actually, %x takes an int, not a hex. C doesn't have a hex type.
>>>Actually, %x takes an unsigned int.
>>4.9.6.1 of C89:
>>d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
>>Sure looks like int to me.
>Interesting. C99 7.19.6.1p8:
>o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
>Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?
I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

I consider the second of the paragraphs to be a refinement of the first,
with the first giving the overview and the second the specifics. Thus
I see no contradiction between versions: as far as I am concerned, both
C89 and C99 specify that %x and %X require unsigned int.
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block
Feb 18 '08 #15
On Feb 18, 12:32 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
In article <7J-dnX6UeKWCWiTanZ 2dnUVZ8sDin...@ bt.com>,
Richard Heathfield <r...@see.sig.i nvalidwrote:
Harald van D?k said:
On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
Keith Thompson said:
Richard Heathfield <r...@see.sig.i nvalidwrites:
Actually, %x takes an int, not a hex. C doesn't have a hex type.
Actually, %x takes an unsigned int.
4.9.6.1 of C89:
d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
Sure looks like int to me.
Interesting. C99 7.19.6.1p8:
o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".
So this means that the ISO standard was actually different from
the ANSI one (because the ISO one has two paragraphs, one for 'i,d',
and another one for 'o,u,x,X')? Is there a list of changes somewhere?

Yevgen
Feb 18 '08 #16
Walter Roberson said:

<snip>
I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

I consider the second of the paragraphs to be a refinement of the first,
with the first giving the overview and the second the specifics. Thus
I see no contradiction between versions: as far as I am concerned, both
C89 and C99 specify that %x and %X require unsigned int.
Thank you, Walter. I have amended my C89 draft accordingly (because
otherwise I'll only make the same stupid mistake again!).

And, of course, my apologies to all, for posting misleading information
upthread.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Feb 18 '08 #17
Walter Roberson <ro******@ibd.n rc-cnrc.gc.cawrote :
>
I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".
That's interesting, *my* nearly-official copy (what was sent to ANSI for
publication) matches ANSI/ISO C90: the first paragraph is for "d" and
"i" and says "int", the second paragraph is for "o", "u", "x", and "X"
and says "unsigned int". Are you sure you're not misreading it? I
sincerely doubt that ANSI change the camera-ready copy.

-Larry Jones

You know how Einstein got bad grades as a kid? Well MINE are even WORSE!
-- Calvin
Feb 18 '08 #18
Mark Bluemel <ma**********@p obox.comwrites:
Keith Thompson wrote:
>... unsigned long is very
often the same size as unsigned long, but it's not guaranteed.

Is this the Schroedinger C compiler we're talking about here?
Yes and no.

What I meant is that unsigned long is very often the same size as void*.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 19 '08 #19
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <7J************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>>Harald van D?k said:
>>On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
Keith Thompson said:
Richard Heathfield <rj*@see.sig.in validwrites:
>Actually , %x takes an int, not a hex. C doesn't have a hex type.
>>>>Actually, %x takes an unsigned int.
>>>4.9.6.1 of C89:
>>>d, i, o, u, x, X The int argument is converted to signed decimal ( d
or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
hexadecimal notation ( x or X );
>>>Sure looks like int to me.
>>Interesting . C99 7.19.6.1p8:
>>o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or X)
in the style /dddd/; [...]
>>Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
- and a potentially significant one, since it causes difficulty for those
wishing to program in the common subset of the two languages. I say
"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
as such is suspect in cases like this. Does anyone have a kosher copy of
the "real" C89 in which they could check this out?

I have the official ANSI C89 hard-copy publication. It describes
the integer formats in two related paragraphs, the first of which
is a summary for all of the formats and uses "int", and the second
of which is specific to o,u,x,X and uses "unsigned int".

I consider the second of the paragraphs to be a refinement of the first,
with the first giving the overview and the second the specifics. Thus
I see no contradiction between versions: as far as I am concerned, both
C89 and C99 specify that %x and %X require unsigned int.
I have the official ISO C90 PDF publication. Here's what it says:

d,i The int argument is converted to signed decimal in the style
(-]dddd. The precision specifies the minimum number of digits
to appear, if the value being converted can be represented in
fewer digits, it will be expanded with leading zeros. The
default precision is 1. The result of converting a zero value
with a precision of zero is no characters.

o,u,x,X The unsigned int argument is converted to unsigned octal (o),
unsigned decimal (u), or unsigned hexadecimal notation (x or
X) in the style dddd, the letters abcdef are used for x
conversion and the letters ABCDEF for X conversion. The
precision specifies the minimum number of digits to appear; if
the value being converted can be represented in fewer digits,
it will be expanded with leading zeros. The default precision
is 1. The result of converting a zero value with a precision
of zero is no characters.

(It's not a good PDF copy; there may be typos in the above.)

Does that not match the ANSI C89 standard?

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 19 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4539
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
3
31916
by: android | last post by:
I require a function that takes a double as a parameter and returns the number of decimal places. What is the most efficient way in c# to find out the number of decimal places I have written a function that does it by converting the double to a string. Is there a better way public static int CountDecimalPlaces(double double1) return double1.ToString().Substring(double1.ToString().IndexOf(".")+1).Length Thank yo
1
2516
by: Zeng | last post by:
Hello, I have many fields in my SQL database that are of type decimal(9,3). How do I detect a decimal value (type decimal in C#) will overflow the db column of sql type decimal (9,3)? Is there a way to figure out the min/max constants of decimal(9,3) to compare against in C# to make sure the new value is "in bound"? Thanks! -zeng
6
7534
by: Kevin Chambers | last post by:
Hi there-- I'm having a heck of a time trying to create a field of data type decimal. It seems like, according to the docs, the following two statements should work just fine: ALTER TABLE Table1 ADD COLUMN Field1 DECIMAL(10,2); ALTER TABLE Table1 ADD COLUMN Field1 DECIMAL; Yet both run-time error 3932 "Syntax error in field definition". Using
3
15152
by: minjie | last post by:
When I executed the following in Access: alter table t1 alter column c1 decimal(8,4); I got an error message: "Syntax error in ALTER TABLE statement". I got a similar error when I tried to add a decimal field. I know I can define a DECIMAL data type via Access GUI interface. But isn't there a way to do it directly with a SQL statement? Thanks.
1
10479
by: jmarr02s | last post by:
I am trying to change my Amount column Data Type from Integer to Decimal (precision 9 digits, scale 3, that is 6 digits to the left of decimal and 3 digits to the right of decimal. Here is the error message I received SQL0443N Routine "SYSPROC.ALTOBJ" I sense this is a security issue, something my DBA must resolve and some aspect I do not have permission to do? Thanks,
2
2929
by: balaki | last post by:
Hi All, I am using VB.Net 2003 and Ms-Access 2003. I want to change the data type of fileds programmatically. I could not find any method in vb.net to do this. i) I tried using the sql query "ALTER TABLE TableName ALTER COLUMN FieldName Number" It works for data type like 'Number', 'Memo' etc. But if I want to change to 'Long Integer' (sub type of Number), it does not work. ii) I tried using ADOX as shown below. It shows the 'Operation...
9
5378
by: sillyr | last post by:
Hi - I use Access 2007. I have a two data fields that I would like to add together in a query and then have the query sum the data for the entire table. The problem is that one of the data fields has a data type of number and the other data field has a data type of text. The data filed with the text data type is a combo box with two fields on of which is a number and t he other is text. I tried to use the functions Val and Cint, but am not...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.