473,944 Members | 7,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.....obviou sly that gives me serious
data issues.

Thanks!

-v
Nov 16 '05 #1
3 11229
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.....obviou sly 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.ToSt ring() it will remove the trailing 0 , if you do
double_var.ToSt ring("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*******@disc ussions.microso ft.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.....obviou sly that gives me serious
data issues.

Thanks!

-v

Nov 16 '05 #3
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in 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.ToSt ring() it will remove the trailing 0 , if you do
double_var.ToSt ring("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.co m>
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
3286
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 the end. e.g 4.650 displays as 4.65 the number of decimals I want to display to varies across the page, e.g. I cant say "display the whole with 3
5
15495
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: 45.340000 --> 45.34 27.700000 --> 27.7 55.000000 --> 55 Is there a function that will do this or do I need to write my own?
2
382
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
20121
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
8664
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 example, they may record one reading as 63.45 and the next as 123.1 and a third as 1.32456. That's fine - those can be saved as floating point numbers (very little math is done with these numbers so I'm not too worried about strange floating...
4
1858
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 converted to a double
16
4166
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 for float()" " here's the code ************
6
7779
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 each file that he has us process. He wants this in a Comma Delimited Format.
0
10145
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
9971
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
11545
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...
1
11307
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
10673
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
9868
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
8236
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
6313
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3518
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.