decimal to varchar loosign decimal places

i convert 45.7895 using code below

 CONVERT(varchar(10), TaxRate, 4) + '%'

 and the output is


why the hell its cutting the 95 from the end?
Everything your business needs to build an online store.
First Click DAL
ASP.NET 3.5/sql server/svn hosting
3/19/2009 12:40:20 PM 91979 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 10

Don't know for sure, but maybe it's because of the ,4.  Try ,10 as a test.

C# <---> VB.Net Translator
3/19/2009 1:17:07 PM

 Without knowing the datatype of taxrate, a precise answer is not possible. However here is a fix based on the assumption that the datatype is FLOAT

SET @TaxRate = 45.7895
PRINT @TaxRate
PRINT CONVERT(varchar(10), @TaxRate, 4) + '%' -- 45.78%
PRINT CONVERT(varchar(10), CONVERT(DECIMAL(4,2), @TaxRate), 4) + '%' 


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
3/20/2009 12:50:51 PM

 CONVERT(varchar(10) , 45.123456, 4 ) + '%'

it is giving me correct result as 45.123456%.

please check TaxRate before  this statement . I think it has problem 

for syntax of convert function use the following link

3/20/2009 1:00:28 PM

 Try using 

PRINT CONVERT(varchar(10), CONVERT(DECIMAL(4,2), @TaxRate), 4) + '%'  


 CONVERT(varchar(10), CONVERT(DECIMAL(4,2), TaxRate), 4) + '%'  

to replace 

 CONVERT(varchar(10) , 45.123456, 4 ) + '%'


What is the datatype of the TaxRate column?

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
3/20/2009 1:14:44 PM

Similar Artilces:

convert varchar to decimal and display coln to 3 decimal places in gridview
  Hi  1. In SQL2005, i hv a 'table1' that has a field called 'Col1' of varchar type Now in a procedure, I declare variable '@Col2' of decimal(8,4) type,then fetch value of col1 into col1a(this is of varchar type) like: select @col1a=col1 from table1 where condition.  now i want to put value of @col1a into @col2, so I write: set @col2=cast(@col1a as decimal(8,2)) but its not wrkng,it gvs error:  unable to convert varchar to numeric data type. what is the problem????? 2.  I want to display field in gridview to 3 decimal places...

plz Help: Converting 4 decimal places to 1 decimal place
Hi,I would like to convert 4decimal places to single(1) decimal place.For that i wrote below code. Its working sometimes. ex1:Input: StrAnlPct = "3.0000,2.9833,3.6546,4.65+6,5.54986,81.dsfds"Output: "3.0,2.9,3.6,4.6,5.5,81.d"For first example its working,Ex2:Input: StrAnlPct = "476290.4762,120.0000"For this i m getting error. Error is:    "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex "And    Source Error: At Line 590Line 588:            &...

Formatting a decimal to 2 decimal places
Hi - just testing some code, and the code below returns a number with 3 decimal places (eg. 450.000). Will returning a decimal always give 3 decimal places, and if so, how can I remove the last one? I don't want to use: Return String.Format("{0:C}", decRunningTotal) - as that will automatically add a $ or £ or whatever to the start, and I'd like to control that. I'd really appreciate any help, thanks, Mark Function GetItemTotal() As String objDT = Session("Cart") Dim intCounter As Integer Dim decRunningTotal As Deci...

CLR.NET datatype for decimal is System.String or Decimal
CLR.NET datatype for decimal is System.String or System.Decimal the documentation says System.string while it is mapped to DbType.decimal I need some understanding on this. any help thanks vsv ...

How to get 2 decimal places?
I have one session var and value of it will be double.How can i do it to be in 2 decimal places rounded up to nearest 5cents. eg.21.781 -> 21.10 21.322 -> 21.05 45 -> 45.00 Math.Round Method (Decimal, Int32, MidpointRounding)   Rounds a decimal value to a specified precision. A parameter specifies how to round the value if it is midway between two other numbers. Namespace: System Parameters d A decimal number to be rounded. decimals The number of significant decimal places (precision) in the return value. mode Specification for how to round d...

inserting a decimal number to stored proc. with decimal parameter
I'm trying to enter large number 99999999, (8 digits) converting to decimal in .NET, then using that as a parameter in stored proc. which has a decimal type (decimal(15,2) as a parameter. C#:if (txtAnnualizedSaving.Text.Trim() != string.Empty) {try { sdata.AnnualizedSaving = Convert.ToDecimal(txtAnnualizedSaving.Text); // only for testing ....scale = (System.Decimal.GetBits(sdata.AnnualizedSaving)[3] >> 16) & 31; }catch { sdata.AnnualizedSaving = 0; } }   ... In the business object I have the following code:private bool UpdateData() {bool ret = false; try ...

How to round off the decimal value to 4 places in VB.NET
Iam getting the result ddlintresult as some 12.344444444444444444444  Dim ddlintresult As Decimal = Convert.ToDecimal(ddlint / lval)  How can i round off the values as 12.3445 Any suggestions or solutions are appreciated    Fred--Thats what my buddies call me Mark this as Answer, if this reply answers your post Math.Round has overloads to do exactly this.   Thanks ShadosFred--Thats what my buddies call me Mark this as Answer, if this reply answers your post...

decimal places
Hi  I am writing a custom control  shown in the code below that extends the textbox controlOne of the extended methods (OnLoad) should add a javascript attribute to the page that on loosing focus from the textbox converts the text box to a number then rounds it to 2 decimal places and places the value back in the textboxunfortunately this doesnt seem to work correctlyI'm new to .net and web dev in general could anybody see errors in what i'm doing or point out an easier way of doing this. (can't use custom validator as it involves changing hundreds of textboxes ove...

Decimal places..
Hey everyone :) I'm having a problem formatting a number to two decimal places. Here's the code: Aspx page <% iFileSize = 9496296; %> <td align="RIGHT">                                <% = FormatNumber(iFileSize / 1048576)%> M</td>   C# Page public static string FormatNumber(double oNumValue)    {        double strResult = 0;     ...

Decimal Places
 Hi everyone... My doubt it's simple... I'm a begginer... It's possible to define the number of decimal places in the creation of a datacolumn and then add this column to a datatable...Thanks... the amazing real A pak Yes, you set the format string.  There are Standard Numeric Format Strings, and if none of those are what you want, you can use Custom Numeric Format Strings.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Hi realapak,   It's possible to define the number of decimal places in the creation o...

Decimal Places
I've got report where the field I'm display is text, sometimes it will be numeric other times not. When it's numeric I'm rounding to apply decimal places. The problem comes in when I get a value like 5.004 and I want the report to round to one decimal place. It displays the number as just 5, not 5.0 If I try to use the general Format and apply something like '###.#' it doesn't work. It just diplays the ###.# for all fields. Any ideas on how to make the decimal point show even if it's zero? Thanks, Suzanne I make the format ###,##0.0 Th...

decimal place
I have two numbers 100.00 and 50.00 when I subtract them I get 50 but I want 50.00 how do I tell it to keep the decimal place? Any help would be appreciated. Christopher Burger Hello Christopher M Burger wrote: > > I have two numbers 100.00 and 50.00 when I subtract them I get 50 but I want > 50.00 how do I tell it to keep the decimal place? $ perl -we 'printf "%.2f\n", 50;' perldoc -f printf perldoc -f sprintf /Stefan Christopher M Burger wrote: > I have two numbers 100.00 and 50.00 when I subtract them I get 50 but > I want=2...

How to validate a decimal value with 2 digits after decimal point (de decimal point is a comma)
  I am a newbee, I have a Textbox where de user must write the price of an object. How can I validate de data entry in the Textbox (it must be a valid decimal with 2 digits after decimal point), and my pages are in  Portuguese so the decimal point to be accepted must be a comma   thanks  well you can do something like followig:  suppose TextBox1.Text = 123456,789 then you can say if(TextBox1.Text.Contains(",") ) {     int index1 = TextBox1.Text.IndexOf(",") +1;     int index2 = TextBox1.Text.IndexOf(...

Trying to get and display a number as it is in the DB (with two decimal places), not rounded
Hi,I am running a command in my aspx page that calls a SP that retrieves data from the DB. But the numbers stored in the DB with several digital places are displayed in the web page rounded and without decimal places.Sub show_Q(of_num)   Dim CmdShow As New SqlCommand("detail_Q", strConnection)  CmdShow.CommandType = CommandType.StoredProcedure   CmdShow.Parameters.Add(New SqlParameter("@Offer_id", SqlDbType.bigint))  CmdShow.Parameters("@Offer_id").Value = of_num   CmdShow.Parameters.Add(New SqlParameter("@Caliber_Q", SqlDbType.Decimal, 5))  CmdShow.Parameter...

Web resources about - decimal to varchar loosign decimal places -

Penny (Irish pre-decimal coin) - Wikipedia, the free encyclopedia
The penny (1d) ( Irish : pingin ) coin was the third smallest denomination of the pre-decimal Irish pound , worth 1/240 of a pound or 1/12 of ...

Dewey Decimal Classification - Wikipedia, the free encyclopedia
This highly organized system categorizes books on library shelves in an efficient, specific and repeatable order that makes it easy to find any ...

Decimal Rounding on the App Store on iTunes
Get Decimal Rounding on the App Store. See screenshots and ratings, and read customer reviews.

Dewey Decimal Tattoo - Flickr - Photo Sharing!
Children's librarians represent.

Math of the Day: Sesame Street’s The Count Reads Pi to 10,000 Decimal Places
... has created a true monster out of your favorite Sesame Street vampire, with audio of The Count reading every digit of Pi out 10,000 decimal ...

Paul Harapin heads Decimal Software after VCE ousting
Former VCE Asia-Pacific boss, Paul Harapin, has taken over as CEO of Decimal Software.

Feeling green: the dangers of decimal currency
The curious case of possibly toxic coins, via Austria and a devastatingly original idea for Canberra.

Jobless Rates With Another Decimal
The BLS reported a jobless rate of 8.3% for both January and February. Adding an extra decimal, the unemployment rates would actually be 8.26% ...

JPMorgan Sued by Trader Over $3 Million Decimal Point
JPMorgan Chase & Co. is being sued by a trader who says he accepted a contract from the investment bank because a typographical error made him ...

.Decimal Archive - Houston Gamer
It was only back in August when newly-formed Houston game studio Orb Interactive launched a Kickstarter campaign for “.Decimal”, a sci-fi take ...

Resources last updated: 12/3/2015 4:02:40 AM