
#------------------
sub yearToYearMonth {
#------------------

    use Number::Format qw{round};
    
    my $year = shift;
    if ( not $year ) { return; }

    my ($y,$frac) = split('\.', $year);
    $frac = '0.'. $frac;
    
    my $month = $frac * 12; # get decimal months.
    $month = round($month,0);

    # print "Y:$y Frac:$frac Month:$month<br>\n";

    return $y. q{Y}. $month. q{M};

}



#---------------
sub scoreToGrade {
#---------------

    my ($score, $readinglevel) = @_;

    if ( not $readinglevel ) { return; }

    
    my %rd_LevelToGrade = ( '0' => 0.1, 1 => 0.3, 2 => 0.6, 3 => 1.0, 4 => 1.2,
			    6 => 1.3, 8 => 1.4, 10 => 1.5, 12 => 1.6, 14 => 1.7,
			    16 => 1.9, 18 => '2.0', 20 => 2.3, 24 => 2.6, 28 => 2.9,
			    30 => 3.3, 34 => 3.6, 38 => 3.9);


    my %rd_ScoreToGrade = (
	50 => 1.9, 51 => 1.9, 52 => 1.9, 53 => 1.9, 54 => '2.0',
	55 => 2.1, 56 => 2.2, 57 => 2.3, 58 => 2.4,
	59 => 2.5, 60 => 2.6, 
	61 => 2.7, 62 => 2.8, 63 => 2.9, 64 => '3.0', 
	65 => 3.1, 66 => 3.2, 67 => 3.3, 68 => 3.4,
	69 => 3.5, 70 => 3.6, 71 => 3.7, 72 => 3.8, 73 => 3.9, 
	74 => '4.0', 75 => 4.1, 76 => 4.2, 77 => 4.3, 78 => 4.4, 79 => 4.5,
	80 => 4.6, 81 => 4.7, 82 => 4.8, 83 => 4.9, 84 => '5.0', 85 => 5.1, 86 => 5.6, 
	87 => 5.3, 88 => 5.4, 89 => 5.5, 90 => 5.6, 91 => 5.7, 92 => 5.8, 93 => 5.9, 
	94 => '6.0', 95 => 6.1, 96 => 6.2, 97 => 6.3, 98 => 6.4, 99 => 6.5, '100' => '6.6',
	101 => 6.6, 102 => 6.8, 103 => 6.9, 
	104 => '7.0', 105 => 7.1, 106 => 7.2, 107 => 7.3, 108 => 7.4, 109 => 7.5, '110' => '7.6',
	111 => 7.7, 112 => 7.8, 113 => 7.9, 114 => '8.0', 115 => 8.1, 116 => 8.2, 117 => 8.3, 118 => 8.4, 
	119 => 8.5, 120 => 8.6, 121 => 8.7, 122 => 8.8, 123 => 8.9, 124 => 8.9, 125 => 8.9, 126 => 8.9,
	127 => 8.9, 128 => 8.9 );


    if ( $readinglevel eq '40K' ) { return '4.0'; }
    

    if ( $readinglevel < 40 ) {

	foreach my $key ( sort { $b <=> $a } keys %rd_LevelToGrade ) {
	    # print qq{K:$key };
	    if ( $readinglevel >= $key ) {
		# print qq{<br><b>Match: K:$key RL:$readinglevel</b><br>\n};
		return $rd_LevelToGrade{ $key };
	    }
	}

    } else { # else reading level >= 40

	$score += $readinglevel; # add both together for this

	if ( $g_DRA3 ) { # DRA 3 mode
	    $score += 6;
	    # testing output: print qq{<div>DRA 3 Mode; Increase by 6<br>\n};
	}
	

	foreach my $key ( sort { $b <=> $a } keys %rd_ScoreToGrade ) {
	    # print qq{K:$key };
	    if ( $score >= $key ) {
		# print qq{<b>Match: S:$score K:$key V:$rd_ScoreToGrade{$key}</b><br>\n};
		return $rd_ScoreToGrade{ $key };
	    }
	}

    }

    return 'NA';
}


# Don't erase this!
1;
