Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have 2 fields in a table namely cost price, selling price.
My project is working like this:-

Cost price * 2= selling price.

so if i enter 21928 as cost price, then after it gets multiplied by 2 it comes as 43856

i want this selling price to make 44000. I mean i want to make rounded off to nearest thousand so that last 3 digits comes zero always.

I have written the code.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Configuration;
using System.Data;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Reporting;
using CrystalDecisions.Web;

/// 
/// Summary description for JewelleryHelper
/// 
 public class JewelleryHelper
{
    /// 
    /// Get encoded selling price
    /// 
    /// Selling price
    /// Encoded selling price
    public static string GetEncodedSellingPrice(string price)
    {
        char[] arrPrice = Math.Round(double.Parse(price) * 2).ToString().ToCharArray();
       string finalSellingPrice = string.Empty;
        //Populating price in encoded format
        foreach (char letter in arrPrice)
        {
            finalSellingPrice += GetEncodedLetter(letter);
        }

Can anyone please tell me.

Please

Thanks
Sudeshna
Posted
Updated 11-Feb-15 23:14pm
v2

1 solution

Try Math.Round(Decimal.Parse(price) / 1000d, 0) * 1000;
 
Share this answer
 
Comments
sudeshna from bangkok 12-Feb-15 5:12am    
I dont have any decimal in my cost price value. whatever i will enter it in double like 23897 or 21784 or 45230
sudeshna from bangkok 12-Feb-15 5:13am    
So shall i use Decimal or Double?
Abhinav S 12-Feb-15 5:13am    
Try Double.
sudeshna from bangkok 12-Feb-15 5:15am    
showing error that cannot implicitly convert double to char[]
sudeshna from bangkok 12-Feb-15 5:18am    
showing error

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