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

Significant Figures/Digits.

4
Hi All!

Have a question that I cant get my head around the problem of storing significant digits with a value.


In C# you can define:
decimal d = 1.10M

When you print it and or use it, the 1.10 is stored in side. And not rounded like double (gives 1.1 ).

But storing the litle bastard is more tricky.

Storing as:
nvarchar(11) gives 1.10.
decimal(8,3) gives 1.100 as well as numeric().


So is there a nice way to store it in a proper way (Which is type safe.)??

Regards
Daniel
Aug 12 '08 #1
6 4403
code green
1,726 Expert 1GB
Not quite sure what you are geting at. Your examples show the data being stored as specified. What are you trying to do?
Just to avoid confusion do you mean significant figures or precision?
Aug 12 '08 #2
ck9663
2,878 Expert 2GB
Or use ROUND.

If it's a question of display, handle it on your front-end.

-- CK
Aug 12 '08 #3
draft
4
Both valid points.

But there is a difference between 1.10 and 1.100.

So if the user inputs that for ex. 5.1% should be copper in a chemical composition.

That means that it can range from 5.05% to 5.14%
But if he puts 5.10% then the range is 5.095% to 5.104%

This is needed for calculations. And can be done without a prob. But storing them as entered.. is different thing. Cant store them as decimal because it adds zeros to the end...



/D
Aug 13 '08 #4
code green
1,726 Expert 1GB
So the problem is you wish the data to be stored exactly as entered, without the database engine strippiing or adding trailing zeroes.
Unfortunateley, with all the numeric data types the significant figures are specified at the creation of the field.
My immediate thought is converting the data to a string and using a TEXT or VARCHAR field.
I think these preserve the data exactly as entered. So long as the calculations program casts them correctly.
Aug 13 '08 #5
draft
4
So the problem is you wish the data to be stored exactly as entered, without the database engine strippiing or adding trailing zeroes.
Unfortunateley, with all the numeric data types the significant figures are specified at the creation of the field.
My immediate thought is converting the data to a string and using a TEXT or VARCHAR field.
I think these preserve the data exactly as entered. So long as the calculations program casts them correctly.
Right on the spot here :)

I have tested every combination that is possible (almost not the stupid). And for now I have to use the varchar() to store the exact number.

A bit addtional coding but.. Small price to pay. I can hope that SQL2008 has some proper number storing stereotype.

Thanks for your time.
/D
Aug 13 '08 #6
code green
1,726 Expert 1GB
Well done.
Be careful to specify a VARCHAR width slightly bigger than the maximum number of digits expected
ie 0.000234 is 3 significant figures but with a precision of 6 decimal places and 8 chars in total
Aug 13 '08 #7

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

Similar topics

29
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 --> 3...
2
by: Andy | last post by:
Could anyone tell me how to round off a number to certain significant figures using C++? For example, how to round off a number 12567 to 13000 (2 significant figures)?
3
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 -->...
3
by: BuddyWork | last post by:
Hello, Does .Net support significant figures if so can someone point me to the right direction or example code? Thanks,
7
by: Michael Howes | last post by:
MSDN documentation for format strings seems ambiguous. It's says things like "significant digits or number of decimal places" all over the place. Well those two things are different. How do I...
6
by: Hoelper | last post by:
When creating a Pivot Table in MS Access, why does the table lose significant digits (e.g., 4.45) and only report rounded whole numbers (e.g., 4)? Can this be fixed? FYI, the database table is...
2
by: Mukesh_Singh_Nick | last post by:
What is meant by the "most significant digits" in the following statement? <BLOCKQUOTE> With %g and %G, the precision modifier determines the maximum number of significant digits...
2
by: mrshrinkray | last post by:
I feel a bit ashamed asking this after 6 years of C#, but is there a format string for significant figures before the decimal place? e.g. 2,354,856: 1 sf = 2,000,000 2 sf = 2,400,000 3 sf =...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.