473,404 Members | 2,170 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,404 software developers and data experts.

Trailing zeros and floats

I need to store money values in C# and I noticed when using
a float, the trailing zero was trimmed off automatically.
I don't want this, is there a native type that will *not*
do this so I can have my trailing zeros?

I want $0.10 not $0.1.....obviously that gives me serious
data issues.

Thanks!

-v
Nov 16 '05 #1
3 11104
On Tue, 14 Dec 2004 04:22:27 -0800, V. Jenks wrote:
I need to store money values in C# and I noticed when using
a float, the trailing zero was trimmed off automatically.
I don't want this, is there a native type that will *not*
do this so I can have my trailing zeros?

I want $0.10 not $0.1.....obviously that gives me serious
data issues.


Either way the actual numerical value is .1. You are talking display value
vs stored value. If you want to display a number formatted to two decimal
places, then you use the appropriate format string.
--
Tom Porterfield
Nov 16 '05 #2
Hi,

Please note that you are confusing two different things, how the number is
store as a number and how it's displayed either as a number or as a
currency.
if you do double_var.ToString() it will remove the trailing 0 , if you do
double_var.ToString("C") you will get the currency representation of that
number.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"V. Jenks" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
I need to store money values in C# and I noticed when using
a float, the trailing zero was trimmed off automatically.
I don't want this, is there a native type that will *not*
do this so I can have my trailing zeros?

I want $0.10 not $0.1.....obviously that gives me serious
data issues.

Thanks!

-v

Nov 16 '05 #3
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us>> wrote:
Please note that you are confusing two different things, how the number is
store as a number and how it's displayed either as a number or as a
currency.
if you do double_var.ToString() it will remove the trailing 0 , if you do
double_var.ToString("C") you will get the currency representation of that
number.


Note, however, that decimals *do* keep their trailing zeroes (in stored
form) as of 1.1. Decimal tends to be better for financial purposes
anyway.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

1
by: BARBARA FLOYD | last post by:
Hi, I have an ASP file which is opened in MS Excel. I have used the "formatNumber" function to set the number of decimals for variables which are displayed. however Excel cuts off any zeros at...
5
by: Jason | last post by:
I have a column defined as DECIMAL(10,6). I want to display it as a string but I do not want the trailing zeros. I cannot seem to get CAST or CONVERT or STR to exclude the zeros. Examples:...
2
by: Keali | last post by:
for example: A1 = 123 A1=123000 <- final result A1 =1234 A1=123400<- final result A1=1 A1=100000<-final result
15
by: Bob | last post by:
I'm about to convert to string and use regex, but I thought there must be something I'm missing here that already exists. Bob
9
by: Chester | last post by:
I'm working on an app that records data collected by service technicians (VB.Net front-end, SQL Server 2000 back end). The technicians need to record numbers with varying scale and precision. For...
4
by: snooglets7 | last post by:
Hey there, I need to store the trailing zeros when I convert a numerical string into a double...I jsut don't know how. I.E. txtLimDist.text = 10.00 (user enters this in the GUI) This gets...
16
by: luca bertini | last post by:
Hi, i have strings which look like money values (ie 34.45) is there a way to convert them into float variables? everytime i try I get this error: "numb = float(my_line) ValueError: empty string...
6
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for...
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: 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...
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
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...
0
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...

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.