473,811 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get 0.000001 with printf?

Hello,

I'd like to print floating point numbers without trailing zeros.
I tried using %g, but now small numbers are printed in the %e
style ("Style e is used if the exponent from its conversion is
less than -4"). Is there some way to control this number (-4)?
I.e. can I get printf to print something like 0.0000001, but no
trailing zeros? Or should I do this by hand?

Thanks,
Mandar.

Nov 15 '05
21 1998
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
William Hughes <wp*******@hotm ail.com> wrote:
Normally, .2, .20, .200 mean different things, so supressing
the trailing zeros usually a BAD THING.


However, the author of the program may not be in a position to know
which of these is the right one.

As an extreme but realistic example, consider a general-purpose
calculator program. Only the user knows the appropriate precision,
and always presenting resulta to many figures would be hard to read.
A pocket calculator that didn't suppress trailing zeros would be
unpopular.

-- Richard
Nov 15 '05 #11
On Sat, 29 Oct 2005 22:07:29 GMT, in comp.lang.c ,
ga*****@yin.int eraccess.com (Kenny McCormack) wrote:
In article <r1************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote:
Well, fundamentally .2, .20 and .200 cannnot actually mean different
things, so the difference is nothing more than cosmetic. What were you
thinking of?


They mean very different things, as I am sure you are well aware.


No, they mean exactly the same thing. Have you invented a new form of
maths ? :-)
You'd better explain what you're thinking of.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #12
On Sat, 29 Oct 2005 22:22:00 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.or g> wrote:
They certainly can mean different things.
I disagree, but then I'm a physicist and engineer by training. :-)
they can imply different levels of precision. ".2" can (sometimes)
mean anything from 0.15 to 0.25, whereas ".200" can mean anything from
0.1995 to 0.2005 (I'm ignoring the question of whether the endpoints
are included in the range).


The /string/ "0.2" can indeed have a variety of possible underlying
/values/. But then, the same is true of pretty much any printed
representation of a numerical value. So this isn't an especially
useful consideration IMHO.

The number 0.2 is the same, irrespective of how many decimals you
choose to print it to.

I thought we were discussing numbers.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #13
Mark McIntyre wrote:
On Sat, 29 Oct 2005 22:07:29 GMT, in comp.lang.c ,
ga*****@yin.int eraccess.com (Kenny McCormack) wrote:

In article <r1************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote:

Well, fundamentally .2, .20 and .200 cannnot actually mean different
things, so the difference is nothing more than cosmetic. What were you
thinking of?


They mean very different things, as I am sure you are well aware.

No, they mean exactly the same thing. Have you invented a new form of
maths ? :-)
You'd better explain what you're thinking of.


These are obviously different things to anyone who lives in the real
world rather than in the rarefied world of pure number.
modulo rounding algorithm]
0.2 means in [0.15,0.25]
0.20 means in [0.195, 0.205]
0.200 means in [0.1995, 0.2005]
Nov 15 '05 #14
On Sun, 30 Oct 2005 17:35:42 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthl ink.net> wrote:
These are obviously different things to anyone who lives in the real
world rather than in the rarefied world of pure number.
modulo rounding algorithm]
0.2 means in [0.15,0.25]
0.20 means in [0.195, 0.205]
0.200 means in [0.1995, 0.2005]


I completely disagree, and believe that your statement above is
classically muddle-headed.

However this isn't a C question so lets move along.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #15
Mark McIntyre <ma**********@s pamcop.net> writes:
On Sat, 29 Oct 2005 22:22:00 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.or g> wrote:
They certainly can mean different things.


I disagree, but then I'm a physicist and engineer by training. :-)
they can imply different levels of precision. ".2" can (sometimes)
mean anything from 0.15 to 0.25, whereas ".200" can mean anything from
0.1995 to 0.2005 (I'm ignoring the question of whether the endpoints
are included in the range).


The /string/ "0.2" can indeed have a variety of possible underlying
/values/. But then, the same is true of pretty much any printed
representation of a numerical value. So this isn't an especially
useful consideration IMHO.

The number 0.2 is the same, irrespective of how many decimals you
choose to print it to.

I thought we were discussing numbers.


Certainly the *numbers" 0.2, 0.20, and 0.200 are exactly the same. As
strings, they're obviously different, and as strings representing
numbers they can denote different precisions.

Since the topic of this thread involves printf(), it seems reasonable
to assume that we're talking about them as strings representating
numbers, not necessarily as numbers.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #16
On Sun, 30 Oct 2005 19:17:46 +0000, in comp.lang.c , Mark McIntyre
<ma**********@s pamcop.net> wrote:
I completely disagree, and believe that your statement above is
classically muddle-headed.


Er, apologies, I missed out at least some indication of humour here.

I /do/ disagree with you, but I consider this very much a friendly
disagreement and wanted to apologise in advance if my earlier post
seemed unduly rude.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #17
On Sun, 30 Oct 2005 19:58:34 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.or g> wrote:
Certainly the *numbers" 0.2, 0.20, and 0.200 are exactly the same. As
strings, they're obviously different, and as strings representing
numbers they can denote different precisions.
Yes, of course. But lets remember that the OP wanted to remove
trailing zeros, not round numbers. In this context, there's absolutely
no difference between these three values.
Since the topic of this thread involves printf(), it seems reasonable
to assume that we're talking about them as strings representating
numbers, not necessarily as numbers.


I think my point was that *in the context of the numbers the OP wanted
to display*, there was absolutely no difference.

By the way I agree I misunderstood Kenny's point. But in any events I
happen also to think its nonrelevant. Consider that if the project
definition calls for trailing zeros to be removed, then this is what
you do, and you assume that whichever users agreed the spec actually
knew what they were asking for...
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #18
Mark McIntyre wrote:
Keith Thompson <ks***@mib.or g> wrote:
They certainly can mean different things.


I disagree, but then I'm a physicist and engineer by training. :-)
they can imply different levels of precision. ".2" can (sometimes)
mean anything from 0.15 to 0.25, whereas ".200" can mean anything from
0.1995 to 0.2005 (I'm ignoring the question of whether the endpoints
are included in the range).


I thought we were discussing numbers.


If the number is the result of some kind of physical measurement,
then it is normal to include the accuracy of the number. For
example,
Foobar's constant is 0.2000 (to 4 significant figures).

This is undoubtedly a different result to:
Foobar's constant is 0.2 (to 1 significant figure).

Further, it is a common shorthand to suppress the
"(to X s.f.)" bit, and use trailing zeroes to indicate
significant figures.

William Hughes was certainly foolish to say that wanting
to print "0.2" by itself is "stupid". But there are many
common contexts (other than in experimental physics as my
example was) where the reader of the output will be expecting
the output to also encode information about its accuracy.

Nov 15 '05 #19
Kenny McCormack wrote:
In article <r1************ *************** *****@4ax.com>,
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Sat, 29 Oct 2005 15:38:15 GMT, in comp.lang.c ,
ga*****@yin.i nteraccess.com (Kenny McCormack) wrote:
In article <sl************ *******@random. yi.org>,
Jordan Abel <jm****@purdue. edu> wrote:
On 2005-10-29, William Hughes <wp*******@hotm ail.com> wrote:
> Normally, .2, .20, .200 mean different things, so supressing
> the trailing zeros usually a BAD THING.

I can't think of any situation where they could mean different
things to C - and C itself does not provide for a way to easily
track significant figures.

Ask yourself who *reads* the output of programs.


Well, fundamentally .2, .20 and .200 cannnot actually mean different
things, so the difference is nothing more than cosmetic. What were you
thinking of?


They mean very different things, as I am sure you are well aware.


They all mean 1/5th.

--
Chris "it's all paraphernalia" Dollin
son of a gun, listen to the plants, breathless.
shifting sands - life in the fast lane.
Nov 15 '05 #20

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

Similar topics

2
5993
by: m_evergreen | last post by:
I would like the numbers 000001 to 999999 to autogenerate in a new database. I will be transfering information from another database and in that database the numbers 000001 to 010000 are already taken. They are used as identifiers in other programs and it would be easier if they were stored as written. Using identity the 0's are eliminated. Is there a way to keep them? Thank you, M
11
5959
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <= 4 */ };
8
2724
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
7
96340
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %% should be used. Wouldn't it have been better (from design perspective) if the same escape character had been used in this case too. Forgive me for posting without verfying things with any standard compiler, i don't have the means for now.
188
17471
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
4
2013
by: pai | last post by:
Hi , Can any one tell me how this statement of printf is behaving . how the last digit is printed int a=2,b=4,c=7; printf("%d",printf("%d %d:",a,b)); //answer to this was 2 4:3
11
3929
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try to do some example to explain, However, after some trying, I confused when I try to do some integer constant division, I know I should do float division something like 3.0/6.0, but I'm still confused where the -0.124709 comes for the following...
34
16015
by: Old Wolf | last post by:
Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?
1
8526
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
0
9605
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
10386
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...
1
10398
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
9204
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
7669
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
5554
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...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
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
3
3017
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.