5 messages in com.mysql.lists.javaRE: decimal formatting (Java solution)
FromSent OnAttachments
Christopher Molnar11 Nov 2004 18:04 
Jeff Mathis12 Nov 2004 08:12 
Marc Dugger12 Nov 2004 10:07 
Mark Matthews12 Nov 2004 10:14 
Christopher Molnar12 Nov 2004 16:04 
Subject:RE: decimal formatting (Java solution)
From:Marc Dugger (ma@socotech.com)
Date:11/12/2004 10:07:03 AM
List:com.mysql.lists.java

Chris-

I've been using the follow code to do what you need:

public class Numbers { public static double truc(double target, int precision) { double factor = Math.pow(10, precision); int result = (int) (target * factor); return result / factor; } public static float truc(float target, int precision) { return (float) truc((double)target, precision); } }

I'm sure this same function is represented somewhere in open source, but this does work.

-md

-----Original Message----- From: Christopher Molnar [mailto:moln@pandmservices.com] Sent: Thursday, November 11, 2004 8:05 PM To: ja@lists.mysql.com Subject: decimal formatting

Hello,

I am finding myself in need of some help. I recently upgraded my java from 1.4.2 to 1.5.0 and have suddenly found one of my apps having problems.

It seems something has changed and I now am getting errors back when saving "12341.1231243" in a database field designed as decimal 10,2

Can anyone point me in the right direction on rounding my decimals to 2 places so that I can solve this problem? I am pulling my hair (what's left of it) out over this and am drawing a blank.

Thanks, -Chris