| Author |
Topic |
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-06-18 : 00:23:23
|
Good day!Could anyone help me to return the "TENTHS" value of a given number?let say ...Number Tenths--------------------------1050 50955 55195.28 95.28 I tried using the modulus operator however it wont work on a number that has a decimal value.How? TNX!Want Philippines to become 1st World COuntry? Go for World War 3... |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-06-18 : 01:28:32
|
| It is better to do this in your presentation layerOtherwise you need to convert it into varchar and extract the digits from thatMadhivananFailing to plan is Planning to fail |
 |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-06-18 : 01:33:41
|
| tnx for the suggestion madhivananIm writing this on a stored proc and this is my basis of my computation. Pls show how?PLAN YOUR WORK, WORK YOUR PLAN. :-)Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-06-18 : 01:34:43
|
| If you need to do calc with it you might be able to get away with something like this:declare @your_num decimal(10,2])set @your_num = '175.25'select @your_num-- divide by 100 to move desired digits to right of decimalselect @your_num = @your_num/100select @your_num-- subtract whole number value remaining on the leftselect @your_num = @your_num - round(@your_num, 0, 1)select @your_num-- multiply by 100 to move them back to the left of decselect @your_num = @your_num * 100select @your_num |
 |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-06-18 : 01:41:11
|
| TNX nathans!how about returning including the decimals?PLAN YOUR WORK, WORK YOUR PLAN. :-)Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-06-18 : 01:41:29
|
| TNX nathans!how about returning including the decimals?PLAN YOUR WORK, WORK YOUR PLAN. :-)Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-06-18 : 02:33:01
|
quote: how about returning including the decimals?
They should be there? Did you run the code i posted?Just curious, what is the purpose of this? |
 |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-06-18 : 02:36:27
|
| declare @your_num decimal(10,2)set @your_num = '175.25'select @your_num--175.25-- divide by 100 to move desired digits to right of decimalselect @your_num = @your_num/100select @your_num--1.75-- subtract whole number value remaining on the leftselect @your_num = @your_num - round(@your_num, 0, 1)select @your_num--.75-- multiply by 100 to move them back to the left of decselect @your_num = @your_num * 100select @your_num--75.00result should be 75.25Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-06-18 : 02:44:21
|
| oops... im away from the server so I cant run this right now :)Increase the scale of the decimal to account for the extra digits.ex.declare @your_num decimal(10,10)Then just cast back to 2 to drop the trailing zeros. |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-06-18 : 08:56:16
|
Take the mod and add the decimal part:SELECT Number, CAST(Number AS INT)%100 + Number - FLOOR(Number) AS TENTHSFROM( SELECT 2050 AS Number UNION ALL SELECT 955 UNION ALL SELECT 195.28) nrsNumber TENTHS -------- ---------------- 2050.00 50.00955.00 55.00195.28 95.28 rockmoose |
 |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-06-20 : 00:14:08
|
| TNX! rockmooseits a credit. :D the FLOOR function is what im looking for. just like the fix function in VB.Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
|