第 2 章 crifanLib.cs之Unit Conversion

目录

2.1. 盎司转千克:ounceToKiloGram
2.2. 千克转盎司:kiloGramToOunce
2.3. 英镑转千克:poundToKiloGram
2.4. 千克转英镑:kiloGramToPound
2.5. 英尺转厘米:inchToCm
2.6. 厘米转英尺:cmToInch

2.1. 盎司转千克:ounceToKiloGram

    public float ounceToKiloGram(float ounce)
    {
        float kiloGram = ounce * 0.028349523125F;

        return kiloGram;
    }
    

例 2.1. ounceToKiloGram的使用范例


        float kiloGram = -1.0F;
        string weightNumberStr = "";
        
        //type1:
        //http://www.amazon.com/Kindle-Fire-HD/dp/B0083PWAPW/ref=lp_1055398_1_1?ie=UTF8&qid=1369487181&sr=1-1
        //<td style="font-weight: bold;text-align:left; font-size: 12px; border-bottom: 1px solid #e2e2e2;" align="right">Weight</td><td style="font-size:12px;">13.9 ounces (395 grams)</td>
        //http://www.amazon.com/Kindle-Paperwhite-Touch-light/dp/B007OZNZG0/ref=lp_1055398_1_2?ie=UTF8&qid=1369487181&sr=1-2
        //<td style="font-weight: bold;text-align:left; font-size: 12px; border-bottom: 1px solid #e2e2e2;" align="right">Weight</td><td style="font-size:12px;">7.5 ounces (213 grams)</td>
        if (!calculatedKiloGram)
        {
            if (crl.extractSingleStr(@"Weight</td><td style=""[^<>]+?"">([\.\d]+) ounces", productHtml, out weightNumberStr))
            {
                float onces = float.Parse(weightNumberStr);
                kiloGram = crl.ounceToKiloGram(onces);