473,791 Members | 2,807 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 9802
On Feb 18, 6:42*pm, Ben Pfaff <b...@cs.stanfo rd.eduwrote:
This was corrected in the corresponding paragraph of
the C99 rationale: [...]
This is all rather unfortunate. K&R2, Plauger, http://flash-gordon.me.uk/ansi.c.txt
and http://www.lysator.liu.se/c/rat/d9.html#4-9-6-1 all say int is
used for o, u, x, X, yet the definitive resource (ISO/IEC 9899:1990)
says they expect unsigned int, and it's a resource I can't get hold of
- I have to rely on quotes on this Newsgroup.

I have the C99 Standard, but my compiler doesn't support it.

--
Martin
Mar 5 '08 #21
In article <wO************ *********@bt.co m>,
Richard Heathfield <rj*@see.sig.in validwrote:
>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.
Extracting the relevant paragraphs of C89 4.9.6.1, starting from
page 133 of the hardcopy (X3.159-1989)

==== page 133 ====

o An option precision gives the minimum number of digits to appear
for the d, i, o, u, x, and X conversions, the number of digits
to appear after the decimal-point character for e, E, and f
conversions, the maximum number of significant digits for the
g and G conversions, or the maximum number of characters to
be written from a string in s conversion. The precision takes
the form of a period (.) followed either by an asterisk *
(described later) or by an option decimal integer; if only the
period is specified, the precision is taken as zero. If the
precision appears with any other conversion specifier, the
behavior is undefined.

o An optional h specifiing that the following d, i, o, u, x, or X
conversion specifier applies to a short int or unsigned short int
argument (the argument will have been promoted according
to the integral promotions, and its value shall be converted to
short int or unsigned short int before printing); an optional h
specifying that a following n conversion specifier applies to
a pointer to a short in argument; an optional l (ell)
specifying that the following d, i, o, u, x, or X conversion
specifier applies to a long int or unsigned long int argument;
an optional l specifying that a following n conversion specifier
applies to a poiner to a long int argument; or an optional L
specifying that a following e, E, f, g, or G conversion specifier
applies to a long double argument. If an h, l or L appears
with any other conversion specifier, the behavior is undefined.
[...]
The flag characters and their meanings are
[...]
# The result is to be converted to an "alternate form". For o
conversions, it increases the precision to force the first digit
of the result to be a zero. For x (or X) conversion, a
nonzero result with have 0x (or 0X) prefixed to it. For
e, E, f, g, and G conversion, the result will always contain
a decimal-point character, even if no digits follow it.
(Normally, a decimal-point character appears in the result of
these conversions only if a digit follows it.) For g and G
conversions, trailing zeros will not be removed from the
result. For other conversions, the behavior is undefined.

==== page 134 ====
0 For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros
(following any indication of sign or base) are used to pad to
the field width; no space padding is performed. If the 0 and -
flags both appear, the 0 flag will be ignored. For d, i, o, u,
x, and X conversions, if a precision is specified, the 0 flag
will be ignored. For other conversions, the behavior is undefined.

The conversion specifiers and their meanings are

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 expanding 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.

c The int argument is converted to an unsigned char, and the
resulting character is written.
====
The text quoted by Richard Heathfield does NOT appear in
C89 4.9.6.1 in the hardcopy version. (I do not know what his source
was.)
--
"When a scientist is ahead of his times, it is often through
misunderstandin g of current, rather than intuition of future truth.
In science there is never any error so gross that it won't one day,
from some perspective, appear prophetic." -- Jean Rostand
Mar 5 '08 #22
Walter Roberson said:
In article <wO************ *********@bt.co m>,
Richard Heathfield <rj*@see.sig.in validwrote:
>>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.

Extracting the relevant paragraphs of C89 4.9.6.1, starting from
page 133 of the hardcopy (X3.159-1989)
Er, Walter, this is weeks old, if not months.
====
The text quoted by Richard Heathfield does NOT appear in
C89 4.9.6.1 in the hardcopy version.
So I understand.
(I do not know what his source was.)
A draft copy of C89. (I have a "real" C99 Standard, but not C89.)

--
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
Mar 5 '08 #23
In article <6d************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Walter Roberson said:
>Extracting the relevant paragraphs of C89 4.9.6.1, starting from
page 133 of the hardcopy (X3.159-1989)
>Er, Walter, this is weeks old, if not months.
February 18th actually. But someone responded today (or last night)
in the thread, and when I went back up the chain I could see there
was still confusion about where exactly the unsigned had appeared,
with the follow-up postings appearing to indicate that the change
appeared in the Rationale for C99, whereas they were in C89 to start with.
So I quoted everything relevant to (hopefully) settle the matter.
--
"The beauties of conception are always superior to those of
expression." -- Walter J. Phillips
Mar 5 '08 #24

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
7533
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
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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
10426
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...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4109
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
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.