Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:40:28+00:00 2026-06-12T16:40:28+00:00

I have a requirement to convert fields in float to string , with following

  • 0

I have a requirement to convert fields in float to string, with following restrictions

  1. Need to truncate the results after 6 places after decimal point
  2. Truncate any trailing zeros after decimal

For example:

  1. 17.666655942234 ==> converted to string “17.666655”
  2. 17.6 ==> converted to string “17.6” and not “17.600000”
  3. 17.66 ==> converted to string “17.66”

I have tried the following, but fail for some of the above requirements and also not able to remove the zero’s.

select 
CASE WHEN RIGHT(convert(VARCHAR, cast(cast(product_price as DECIMAL(28,6))  as float)),2) = ".0"
THEN LEFT(convert(VARCHAR, product_price),(CHAR_LENGTH(convert(VARCHAR(15), product_price))-2))
ELSE substring( convert(VARCHAR, cast(cast(product_price as DECIMAL(28,7))  as float)),1, charindex(".",convert(VARCHAR, cast(cast(product_price as DECIMAL(28,7))  as float)))+6) END 
from #TEMP

#TEMP data

id | product_price
-------------------
1  | 17.3435302323
2  | 17.700000000
3  | 17.60
4  | 19.0

I guess, I have complicated the query and a simpler version should exists.

I know this could be easily handled in high level language, but if this could be easily be accommodated in the query itself then please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:40:29+00:00Added an answer on June 12, 2026 at 4:40 pm

    I’m not sure if there is easier way to do that on sybase.

    This example works for me

    declare @val float
    declare @val2 float
    select @val = 17.666655942234 
    select @val2 = 17.66
    select substring(convert(varchar(30),@val), 1, patindex('%.%',convert(varchar(30),@val)))+reverse(convert(varchar(30),convert(int,reverse(substring(convert(varchar(30),@val), patindex('%.%',convert(varchar(30),@val))+1,6))))) as Val,
           substring(convert(varchar(30),@val2), 1, patindex('%.%',convert(varchar(30),@val2)))+reverse(convert(varchar(30),convert(int,reverse(substring(convert(varchar(30),@val2), patindex('%.%',convert(varchar(30),@val2))+1,6))))) as Val2
    

    solution with varchar(15)

    declare @val numeric(10,5)
    declare @val2 numeric(10,5)
    select @val = convert(numeric(10,5),17.666655942234)
    select @val2 = convert(numeric(10,5),17.66)
    select convert(varchar(15),substring(convert(varchar(15),@val), 1, patindex('%.%',convert(varchar(15),@val)))+reverse(convert(varchar(15),convert(int,reverse(substring(convert(varchar(15),@val), patindex('%.%',convert(varchar(15),@val))+1,6)))))) as Val,
           convert(varchar(15),substring(convert(varchar(15),@val2), 1, patindex('%.%',convert(varchar(15),@val2)))+reverse(convert(varchar(15),convert(int,reverse(substring(convert(varchar(15),@val2), patindex('%.%',convert(varchar(15),@val2))+1,6)))))) as Val2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to convert the following types of decimal numbers to exponential
We have a requirement where we need to convert from .wav file to .mp3
I have a requirement to convert LINQ to DataTable. I stole the following Extension
I have a requirement where I have to convert timezone from UTC to a
I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched
In our project we have requirement that, after receiving sms message from third party
I have a specific requirement to convert a stream of bytes into a character
Basically, I have this requirement to convert a present/future weekday to a timestamp. Example:
I have a requirement in project to Convert 24 hours format to 12 hours
I have a requirement to convert the format of video to another format such

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.