Decimal to String

I have a decimal column (9,3) that I want to convert to a right-justified
string without the decimal.  For instance, I would like to convert 1.256 to
"000000001256", or 15.5 to "000000015500". I'd like to be able to do this
within a Select Statement (for a view).  Does anyone have an idea?

-Dave
0
David
10/14/1999 4:30:37 PM
sybase.sqlanywhere.general 32637 articles. 4 followers. Follow

5 Replies
626 Views

Similar Articles

[PageSpeed] 7

David Gerdner wrote:
> 
> I have a decimal column (9,3) that I want to convert to a right-justified
> string without the decimal.  For instance, I would like to convert 1.256 to
> "000000001256", or 15.5 to "000000015500". I'd like to be able to do this
> within a Select Statement (for a view).  Does anyone have an idea?
> 
> -Dave

SELECT RIGHT(REPEAT('0',12) ||
             CAST(CAST(MyColumn * 100 AS integer) AS char(12)),12)
FROM dba.MyTable
0
Kathleen
10/14/1999 6:45:19 PM
Kathleen,
I like that approach!  One word of caution, though...
I've learned to stay away from the Repeat() function if I can avoid it at
all.  Performance can really suck, and just for grins, try sending a
negative number as the repeat argument...  (have a backup handy first!)
If you know you need a fixed number of characters, just make it a
onstant  -  '000000000000'.

Paul Horan
VCI
Springfield, MA

Kathleen Beaumont <kathbeau@earthlink.net> wrote in message
news:380624BF.E32@earthlink.net...
> David Gerdner wrote:
> >
> > I have a decimal column (9,3) that I want to convert to a
right-justified
> > string without the decimal.  For instance, I would like to convert 1.256
to
> > "000000001256", or 15.5 to "000000015500". I'd like to be able to do
this
> > within a Select Statement (for a view).  Does anyone have an idea?
> >
> > -Dave
>
> SELECT RIGHT(REPEAT('0',12) ||
>              CAST(CAST(MyColumn * 100 AS integer) AS char(12)),12)
> FROM dba.MyTable


0
Paul
10/14/1999 9:02:37 PM
There supposedly fixed the negative number parameter problem.  But you 
can bet I'm NOT going to try it. <g>
-- 
Jim Egan [TeamSybase]
Houston, TX
0
eganjp
10/15/1999 4:44:36 AM
Paul Horan wrote:
> If you know you need a fixed number of characters, just make it a
> constant  -  '000000000000'.

Yes, er, ahem, cough-cough... Naturally, I was leaving that optimization
as an exercise for the reader. Good you! You caught on right away!

Kathleen
0
Kathleen
10/15/1999 3:49:18 PM
Kathleen,
>> You caught on right away!
Very impressive smooooooth landing!


0
Mike
10/15/1999 6:42:06 PM
Reply:

Similar Artilces:

Decimal in String to Decimal Number Conversion
I think I'm out of luck after visting DejaNews (hints but no definitive answer), but figured you all are worth a try... :) My PB program imports a text file containing decimal numbers in the format ####.## (e.g., 1234.56), and then converts them to a number to put into a numeric datawindow column. Problem is that if regional settings are set to use the comma as decimal separator and period as thousands separator, then the resulting number from Real(ls_number) is 123456 rather than 1234.56. This is a big problem. The only solution I have so far is to remove the decimal form th...

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 ...

Decimal , string ....
Dear all, I am reading a file with amounts , fixed format 0001321311145 4564646431231 1113123131311 i have to read the values (no problem) and then convert them to a decimal variable with 2 decimals behind the comma. so 13213111,45 45646464312,31 11131231313,11 I am not sure how to convert the string value (13 long) to a dec(11,2) TIA John Dec(stringvar)/100 -- Simon Caldwell Get Real Systems Ltd Holtby Manor, Stamford Bridge Road, York, YO19 5LL Tel +44 (0)1904 481999 Fax +44 (0)1904 481666 Visit us at www.getrealsystems.com Procurement Control S...

string and string[]
hello, whats the difference here between string and string[] thanks "string" denotes an item of type String "string[]" denotes an array of type String itemsThanks, EdMicrosoft MVP - ASP/ASP.NET Gracia mon ami...

string to string[]
Hi, I've got this code : string[] Params; string SQL = "SELECT * FROM T_MANAGEMENT_PAGES"; SqlCommand myCommand = new SqlCommand(SQL, myConnection); myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { Params_Type = myReader.GetValue(0).ToString(); } } catch { } finally { } myReader.Close(); My problem is to obtain Params_Type. But each time, it says : "impossible to convert '[object]' in 'string[]' &quo...

String to decimal
This must have been asked a thousand times but I cannot find the answer. I have a string that I need as a decimal. It goes into a bunch of decimal place precision that caused rounding errors over the course of adding thousands of these numbers together. sting ls_number decimal ld_number ls_number = "42,508.26" ld_number = real( ls_number ) // ld_number is now 42508.2617185 How do I avoid this? Presuming this value is always 2 fixed decimal points, declare as decimal{2} ld_number Or use ld_number = Dec(ls_number) You're jumping between fixed...

String To Decimal
Hi, How can I convert from string (Text Box)  to Decimal (addition some entries then get result) Thanks, http://tinyurl.com/aqpgm To Decimal method. Eric RamseurRainbow Portal 2.0 AdminDownload Rainbow 2.0!!Rainbow Code Rainbow Portal CommunityC# 2005 Group Please can u write thz method   sorry for disturbing cavalry wrote: Please can u write thz method Scroll down just a little bit on that link above and therz the method in both VB and C#"If you make it idiot proof, they'll build a better idiot" Hi again, i see the like but Access to the req...

String and String[]
What will be the advantage of using myString: String[10] over myString: String Man wrote: > What will be the advantage of using > myString: String[10] > over > myString: String "String[10]" is a fixed-length, statically allocated, Ansi-based ShortString. "String" is a dynamic-length, dynamically allocated, reference counted, Ansi-based or Unicode-based (depening on Delphi version) Long string. Unless you absolutely need the static, fixed length nature of ShortString, such as in records that interact with external systems, you should stay ...

String and string?
Hi guys, I was wondering the difference between small letter string type and a capital letter String type. Does anyone know about this? Highly appreciate for your answers! Thankz! The "proper" version is String, as it references the System.String class of the .NET Framework Class Library. The ability to use string is provided by C#, where it is an alias to String. Similarly, the "proper" version of an integer is Int32, as it references System.Int32.  The ability to use int is provided by C#, and the ability to use Integer is provided by VB.NET, and both int and Integer are aliases...

string() = string()
this code does not work (not instance of object) Dim Items(), Other() As String Items = New String() {"A","B","C"} Other = New String() {} Other = Items how can I get all the values ? angiras Hi, If I understand your requirement correctly, this should do it Dim Items() As String = {"A", "B", "C"} Dim Other(Items.Length - 1) As String Items.CopyTo(Other, 0) To more closely match you code above, but this will be less efficient Dim Items(), Other() As String ...

What generals generally do
Reading a McChrystal thread elsewhere, I came across someone quoting a US general http://en.wikipedia.org/wiki/Smedley_Butler > I spent 33 years and four months in active military service and > during that period I spent most of my time as a high class thug for > Big Business, for Wall Street and the bankers. In short, I was a > racketeer, a gangster for capitalism. I helped make Mexico and > especially Tampico safe for American oil interests in 1914. I helped > make Haiti and Cuba a decent place for the National City Bank boys to > collect revenues in. I ...

a string in a string in a string in my code behind....
I know my title talk about code-behind, but this is really a client-side problem (and surely a newby one too, sorry about that).I have a javascript function that my make a little text appear when the onmouseover event of a link is activated.So, normally, if my link was inside my html code, it would be something like this:<a href = "whocare.com"  onmouseover="poplink('I want to test something');">test</a>BUT, for some reason, I have to write this part in code behind with the LiteralControl function....and that will give something like that:this.Controls.Add(new LiteralCo...

m_AVP As IDictionary(Of String, String) = New Dictionary(Of String, String) ,not defined?
   I am creating a usercontrol (ascx,ascx.vb)   I have used Imports system.Collections Imports system.Collections.Generic     Private m_AttributeValuePair As IDictionary(Of String, String) = New Dictionary(Of String, String)     But I am gettting an error “Type Dictionary is not defined”   And also I am getting intelisense to type the line But what is the reason for my error ? How can I get escape from the error ?         this error is not showing today  ...

Convert string to decimal
I have strings like this: 0.8933 - 0.7733 - 1.2234I notice that the ones that are 0.xxx and near to 1, they are round up to 1.0000 when I convert the strings to decimal.I need them to remain the same value as decimal to insert them in the db.How can I achieve it and avoid rounding?Many thanks. Use decimal.Parse. Look at the following example page: aspx: <asp:TextBox runat="server" ID='txtNumber'></asp:TextBox><asp:Button runat="server" ID='btnExecute' Text='execute'          &nb...

Web resources about - Decimal to String - sybase.sqlanywhere.general

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/5/2015 4:04:03 AM