0

I have function to calculate price as follows:

public ActionResult updatePrice(int pageCount,int detid ,int spec)
        {
            double amt = 0.00;

            double final = 0.00;
            using(APM context = new APM())
            {
                var lst = (from s in context.M_Spec
                           join p in context.M_SpecDetails on s.ID equals p.SpecID

                           where p.SpecificationID == spec && p.SpecID == detid
                           select new
                           {
                              amount = (double) p.Rate
                           }).ToList();


                foreach( var s in lst)
                {
                    amt = (pageCount - 10) * (s.amount) ;
                }

                var def = (from s in context.M_Spec where s.ID == detid 
                           select new
                           {
                               defamt = (double)s.DefaultCost
                           }).ToList();


                foreach (var s in def)
                {
                    final =  (s.defamt) + amt;
                }             

            }

            return Json(new { success = true, Amount = final});
        }

Finally get the answer like final = 2130.0 and I passed it to the ajax success using json as above and I get the result at ajax success as 2130.How can I overcome this problem?

2
  • You have to send it as a string. Commented Jul 8, 2016 at 9:33
  • 2130.0 == 2130, so you are getting 2130.0. Ideally you should format the resulting value on the UI. Commented Jul 8, 2016 at 9:58

2 Answers 2

1

When you pass in a value type it contains only meaningful digits, zeros after decimal point are being dropped. Also for value types, .NET has cultural based formatting. The way you can get your wanted result by either passing a plain string or forwarding string format a long side with value.

Sign up to request clarification or add additional context in comments.

Comments

1

The zeroes after decimal 2130.0 are considered insignificant while the JSON conversion here, therefore are dropped off, but the significant figures other than zeroes will remain preserved i.e- 2130.05 will remain 2130.05.

If you want to preserve the format pass it as a string. It will work.

Hope it helps..

Comments

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.