1

I want to remove . from all decimal value from my query output like if i use

select(32.00) output should come 3200
select(32.50) output should come 3250
select(32.05) output should come 3205

Is there is any function present to give me this output i dont want 3200.00 as output if anyone know plz tell me how ?

1
  • 1
    You really should specify what data type your 32.05 is. Is it money, decimal, real, double, ...? Commented Oct 7, 2011 at 6:29

2 Answers 2

10

You could multiply by 100 and cast to an integer:

=> select cast(32.00*100 as integer);
 int4 
------
 3200

That will give you an integer. If your values aren't the decimal(n,2) that they appear to be, then you might want to pull out round, floor, or ceil to make your desired rounding or truncation explicit:

=> select floor(23.025 * 100), ceil(23.025 * 100), round(23.025 * 100);
 floor | ceil | round 
-------+------+-------
  2302 | 2303 |  2303
Sign up to request clarification or add additional context in comments.

2 Comments

One would think this would not work if the value was 32.001 but apparently it does
@ertx: The cast-to-int will work but it will truncate. I added a couple more options in case the incoming data isn't the decimal(n,2) that it appears to be.
1

You could try:

SELECT replace(CAST(your_field AS text),'.','')
FROM your_table

1 Comment

@mu is too short: is this better? Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.