473,839 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting numbers with commas in TSQL

Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?

Cheers
Dave
Jul 20 '05 #1
6 44749

"David Sharp" <da**@daveandca z.freeserve.co. uk> wrote in message
news:ca******** *************** **@posting.goog le.com...
Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?
Yes, do it at your presentation layer, not at the DB layer.


Cheers
Dave

Jul 20 '05 #2
Hi Dave

You shouldnt really do any formatting of numbers in the database. It
should be done on the client.

Sam

da**@daveandcaz .freeserve.co.u k (David Sharp) wrote in message news:<ca******* *************** ***@posting.goo gle.com>...
Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?

Cheers
Dave

Jul 20 '05 #3
da**@daveandcaz .freeserve.co.u k (David Sharp) wrote in message news:<ca******* *************** ***@posting.goo gle.com>...
Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?

Cheers
Dave

You could do this TSQL by creating your own functions, but you should
probably do it in the front end application instead, if possible. The
format above is incorrect in Spain and Germany, for example - a client
application can retrieve locale information and format the output
accordingly much more easily than doing it on the server side.

Simon
Jul 20 '05 #4

"David Sharp" <da**@daveandca z.freeserve.co. uk> wrote in message
news:ca******** *************** **@posting.goog le.com...
Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?


IMHO, this is a job for the Presentation Layer/GUI. I wouldn't store commas,
or format the numbers for me. I'd rather handle this on the client side so I
am not storing needless data (, and .) in the database, and so I can format
the data properly according to regional setting on the client side.
--
BV.
WebPorgmaster - www.IHeartMyPond.com
Work at Home, Save the Environment - www.amothersdream.com
Jul 20 '05 #5
> Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.

i.e. convert
53000000.12
to
53,000,000.12

I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?

Cheers
Dave

Hi Dave,

If you really want to do it in TSQL. Cast as Money. Then convert
using style 1. "convert(varcha r,cast(myVar as money),1)" - Louis
Jul 20 '05 #6
Thanks to everyone who replied and of course who are absolutely
correct that this sort of data formatting should be done in a
presentation layer rather than the db.

Unfortunately in this specific case, the text is being generated to
annotate a simple calculation performed in a stored proc called by a
trigger and so doesn't have a presentation layer in which to do the
formatting.

Thanks Louis for highlighting a possible solution.

lo************@ hotmail.com (louis nguyen) wrote in message news:<b0******* *************** ***@posting.goo gle.com>...
If you really want to do it in TSQL. Cast as Money. Then convert
using style 1. "convert(varcha r,cast(myVar as money),1)" - Louis

Jul 20 '05 #7

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

Similar topics

9
10437
by: Rowan Chapman | last post by:
Hey all! I'm kinda new to VB but not to programin'. So I know what it is like when you are asked trivial questions. Could some1 please tell me what the syntax would be 2 only allow numerical data into a textbox. thankz in advanced -Ro -------------------------------------------------------------------- " Reality is an illusion caused by lack of alcohol. " --------------------------------------------------------------------
2
1627
by: johkar | last post by:
I picked up the following script from an old post on this newsgroup. It works fine for numbers to two decimal places, but I have a need to format numbers to three decimal spaces from this: 1234.394 to this: 1,234.394 (no rounding). I don't quite follow the reg exp in the variable fmt or what the $1 and $2 do in the myNum replace method. Any enlightenment/help would be appreciated. Thanks, John //FORMATS NUMBERS WITH COMMAS.
0
311
by: Mike | last post by:
I'm trying to come up with a regular expression that matches numbers with commas... but doesn't match numbers formatted without commas. The problem is that I'm trying to parse a file where the columns run together sometimes. For example 987,456,321123,456,78 This matches for the following regular expression ?(\d|,)*\.?\ What I'd like to to is only match up to three numbers between commas so that the preceding example would come back...
22
1814
by: KsAdmin | last post by:
I have a question which has had me stumped for a few days now. I have a form that I add the values of fields together and display the total in a total field. I have the calculations working correctly. My problem is that I would like to change the format of the total from 1234567 to 1,234,567 . Is this possible using javascript? Here is the code that I use to do the calculations. I have edited out all the code that I use to validate the...
7
6406
by: Christopher Robin | last post by:
Hi, I'm trying to find if a function exists that would format a large (> 1000) number with comma notation on a unix type system... I currently have X = 10000; printf("X = %d\n", X); which obviously only prints:
4
2803
by: John Sutor | last post by:
I need some code that, on each keyup event, will take all of the numbers typed into the text box and format as they type to look like this 100 1,000 10,000 100,000 1,000,000 John S
2
1245
by: Smiley | last post by:
In a program I'm creating, I'm trying to calculate a percentage. However, for some reason the calculation is only coming out to 1 decimal place, and I know there's more. Using this code: $gshare = $shareresults / $phenresults; echo "$shareresults / $phenresults = $gshare"; I get the following output: 3,340,000 / 5,180,000 = 0.6
7
16499
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so they can only input numerical values. Is there any way to do this? Currently my formatting works but if the user enters a value manually the formatting is not applied to the new value. Also I haven't found a way to allow only numerical input....
2
2118
by: freemld10 | last post by:
Hi guys, Can someone please help me to Format Numbers with commas. The script below have very large number without commas. To read numbers in trillions and billions are hard, without commas to separate the numbers. By cutting and pasting the JavaScript below into a web editor and you can clearly see what is happening. Please, help. Thank You, freemld10 <html> <head> <script type="text/javascript"> function startTime() { var seconds = 0;
0
9698
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
10589
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10654
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
10297
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
7021
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
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.