473,396 Members | 1,813 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,396 software developers and data experts.

decimal acrobats

Hi

is there a method to trim the number of decimals to a given length.
those numbers are read off a text file, they will need to be atof(ed)
either before or after trimming, whats the right way to do this?
any boost(ers) there?
many thanks
Aug 1 '06 #1
3 1134
Gary Wessle wrote:
is there a method to trim the number of decimals to a given length.
During input or output? For output see 'setprecision' manipulator. For
input, I am not sure of the sensible way of doing that.
those numbers are read off a text file, they will need to be atof(ed)
If you intend to use 'atof' literally, I caution you - it's not a good idea.
Consider using 'strtod' instead.
either before or after trimming, whats the right way to do this?
Use 'strtod', and there is no need to trim during input, AFAIK. Why do you
think you need to trim?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '06 #2
"Victor Bazarov" <v.********@comAcast.netwrites:
Gary Wessle wrote:
is there a method to trim the number of decimals to a given length.

During input or output? For output see 'setprecision' manipulator. For
input, I am not sure of the sensible way of doing that.
those numbers are read off a text file, they will need to be atof(ed)

If you intend to use 'atof' literally, I caution you - it's not a good idea.
Consider using 'strtod' instead.
either before or after trimming, whats the right way to do this?

Use 'strtod', and there is no need to trim during input, AFAIK. Why do you
think you need to trim?
just for the cout format. from .898900000 to .8989 which strtod works,
but if fails to include 4 in this example (from .89890004 still puts
out .8989)
Aug 1 '06 #3
Gary Wessle wrote:
[..]
just for the cout format. from .898900000 to .8989 which strtod works,
but if fails to include 4 in this example (from .89890004 still puts
out .8989)
Post your code and your data, then we can talk. Is it possible that you
are using 'float' where you should be using 'double'?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '06 #4

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

Similar topics

21
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
4
by: Julian Hernandez Gomez | last post by:
Hi ! This is maybe a silly question, but... is there a "easy way" to make eval() convert all floating numbers to Decimal objects and return a Decimal? for example: ...
11
by: Timothy Smith | last post by:
i want to trunkate 199.999 to 199.99 getcontext.prec = 2 isn't what i'm after either, all that does is E's the value. do i really have to use floats to do this?
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
8
by: Gilbert Fine | last post by:
This is a very strange exception raised from somewhere in our program. I have no idea how this happen. And don't know how to reproduce. It just occurs from time to time. Can anyone give me some...
25
by: Lennart Benschop | last post by:
Python has had the Decimal data type for some time now. The Decimal data type is ideal for financial calculations. Using this data type would be more intuitive to computer novices than float as its...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.