Solved

FOrmat Float

Posted on 2006-10-25
4
524 Views
Last Modified: 2011-04-14
Hello all, I have a insert statement (below) in which the @pDifference is a float.  If the variable contains 2.7777764646 for example, I want to format so that the insert just puts 2.7 into the database.  Please help!  Urgent!
0
Comment
Question by:jwebster77
  • 2
4 Comments
 

Author Comment

by:jwebster77
Comment Utility
cast(@pDifference as decimal(5,1))

This is how I did it for anyone interested.
0
 
LVL 26

Expert Comment

by:DireOrbAnt
Comment Utility
SELECGT ROUND(@pDifference, 1) AS RoundedValue
0
 
LVL 23

Accepted Solution

by:
adathelad earned 500 total points
Comment Utility
jwebster77 - your solution will put 2.8 into the database though?

If you want the value rounded down to 2.7 instead:
cast(floor(@pDifference * 10) as decimal(5, 1)) / 10
0
 

Author Comment

by:jwebster77
Comment Utility
Good point.  I am not sure if we want to round down yet or not...  The example show was more for "decimal places" being limited to 1. I'll give you the credit for the answer though, just in case I need to use the floor function!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now