Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Value given is : 123.45000
123.45000000
63.50
Output : 123.45
123.45
63.5

What I have tried:

i have tried using patindex which is not working
Posted
Updated 4-Dec-17 17:29pm

Try this
Double price = 123.45000;
DecimalFormat format = new DecimalFormat("0.####");
System.out.println(format.format(price));
 
Share this answer
 
v2
WITH CTE AS(SELECT 123.45000 AS id
               UNION ALL 
            SELECT 123.45000000 
               UNION ALL 
            SELECT 603.50
           )

SELECT  CAST(id AS FLOAT)AS ID FROM CTE;
---
ID
---
123.45
123.45
603.5
 
Share this answer
 
v2
Comments
Member 13276583 5-Dec-17 2:12am    
Thanks for the solution..
I may have a value where 203.500 in this case i am unable to use replace function
Santosh kumar Pithani 5-Dec-17 2:24am    
Yes, your right i will improve my solution.Thank u!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900