473,395 Members | 1,969 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,395 software developers and data experts.

price formatting

ok, i have a column of data type money and the data that is found in there is entered like this

1.1490
1.2340
1.0590
0.5990
0.5380

what i want to do is have it formatted as such
1149
1234
1059
0599
0538

ive tried using cast, convert, from money to varchar and simplying multiplying the field, replace and trunc but its not happening !!! any code help would be great!

thanks
andreas
Jan 19 '07 #1
7 2216
jai80
30
hi andreas,

Try this :
Expand|Select|Wrap|Line Numbers
  1. declare @a varchar(10)
  2. declare @b varchar(10)
  3. set @a= convert(varchar(10),1.1490)
  4. set @b=Replace(@a,'.','')
  5. select left(@b,4)
  6.  
Let me know if this has solved your problem. Gud Luck!

Cheers,
jai

ok, i have a column of data type money and the data that is found in there is entered like this

1.1490
1.2340
1.0590
0.5990
0.5380

what i want to do is have it formatted as such
1149
1234
1059
0599
0538

ive tried using cast, convert, from money to varchar and simplying multiplying the field, replace and trunc but its not happening !!! any code help would be great!

thanks
andreas
Jan 19 '07 #2
almaz
168 Expert 100+
Recommended pattern is that any data formatting should be performed on the client side.
Jan 19 '07 #3
almaz
168 Expert 100+
If you still want to format the data on server, use the following script:
Expand|Select|Wrap|Line Numbers
  1. declare @t table (price money)
  2. insert @t values (1.1490)
  3. insert @t values (1.2340)
  4. insert @t values (1.0590)
  5. insert @t values (0.5990)
  6. insert @t values (0.5380)
  7.  
  8. select formatted_price = isnull(replicate('0', 4-len(price)), '') + price
  9. from 
  10.     (select price = convert(varchar(10), convert(int,price*1000)) 
  11.     from @t) source
Jan 19 '07 #4
all of the code works perfectly fine, the thing is thought, that in dbo.vwCurrentFuelPrice there has a column CurrentPrice that i want to format in the way i described above. i want to be able to get it every time without having to manually enter the prices 1.1490 etc. thats how it gets put in if you get my drift.. thanks!
Jan 21 '07 #5
all of the code works perfectly fine, the thing is thought, that in dbo.vwCurrentFuelPrice there has a column CurrentPrice that i want to format in the way i described above. i want to be able to get it every time without having to manually enter the prices 1.1490 etc. thats how it gets put in if you get my drift.. thanks!
heres the offending code

declare @a varchar(10)
declare @b varchar(10)

SELECT DateEntered, dbo.Site.SiteCode AS SiteCode, ('0' + DepartmentID) AS FuelCode, convert(varchar(10),CurrentPrice)
FROM dbo.vwCurrentFuelPrice, dbo.Site
WHERE dbo.vwCurrentFuelPrice.SiteID = dbo.Site.SiteID

set @a = convert(varchar(10),dbo.vwCurrentFuelPrice.Current Price)
set @b =Replace(@a,'.','')
select left(@b,4)

that should help explain a bit about what im trying to achieve
Jan 22 '07 #6
iburyak
1,017 Expert 512MB
Try this:

[PHP]
select right('0000' + convert(varchar(10), convert(int, CurrentPrice * 1000)),4) from dbo.vwCurrentFuelPrice[/PHP]
Jan 22 '07 #7
legend! thanks heaps buddy

=)
Jan 22 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: | last post by:
Does anyone know an easy way to put a current gold price on your own website? I've seen the graphic methods that Kitco.com offers, but I'd rather have it pull the value from some gold market...
0
by: cwbp17 | last post by:
Have a datagrid that displays the price column in this format $12,400.00 from a table. Went to the Property Builder of the datagrid and selected the Price column and changed the Data formatting...
3
by: Gigi.com | last post by:
Hi All. I need some help trying to pull prices from a price matrix. Here's an example: >>>> 1000 1500 2000 2500 ----------------------------------------- 1000 ¦ 10.20 ...
0
by: cwbp17 | last post by:
Have a datagrid that displays the price column in this format $12,400.00 from a table. Went to the Property Builder of the datagrid and selected the Price column and changed the Data formatting...
0
by: geoffrey.slinker | last post by:
I have developed a new type of chart. It shows the relative volume for each price during an interval. http://home.att.net/~geoffrey.slinker/maverick/VolumeBars.html I am a Data Visualization...
5
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"?...
1
by: menyki | last post by:
am writing a program to determine the best price that will attract maximum demand. first i had to generate random number to enable me determine the price and quantity demanded at the particular...
3
by: dancole42 | last post by:
I have an InvoiceLines subform on an invoice table. In the subform, I have the following fields that are bound to the actual InvoiceLines table: Class (the type of product) Product (the...
6
by: fniles | last post by:
Say price = 4179.00 or 4179 In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in VB.NET when I do String.Format(price, "#.0"), it returns 4179.00. How can I do Format(price, "#.0") in...
3
by: printline | last post by:
I am need of a simple price calculation script that will give users a price on a Printed Circuit Board. Here is an example: I have a panel that is 18 dm˛. A customers wants 1 PCB that is 100mm...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.