Click here to Skip to main content
14,984,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to convert this code from Java to C#

DecimalFormat rounded = new DecimalFormat("0.0'0'");
            Double yValDub = new Double(rounded.format(yVal));
            return yValDub;

what i Tried is

DecimalFormat rounded = new DecimalFormat("0.0'0'");
            double yValDub = new double?(rounded.format(yVal));
            return yValDub;

1 solution


This may not be the most elegant soloution but I would go for this, I am assuming yval is a numerical value.

decimal yvalDub = decimal yval = decimal.Round(yval, 2, MidpointRounding.AwayFromZero);

Or if there is a chance of a null value use a try parse

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