Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to divide all values in nested list by 2.54 In Flutter

Can you please help me to the division of nested list values in Flutter?

I have a nested list representing boy head circumference data in centimeters. For each list in the outer collection, and for each element in the inner lists, I retrieve the original circumference value in centimeters. Following that, I convert the circumference value from centimeters to inches by dividing it by 2.54. Subsequently, I updated the nested list with the converted circumference value in inches.

  List boyHeadCircumferenceData = [
    [
      31.92128,
      34.94019,
      36.78314,
      38.14913,
      39.24371,
      40.14288,
      40.88935,
      41.51388,
      42.03988,
      42.48701,
      42.8715,
      43.20496,
      43.49653
    ],
    [
      32.37241,
      35.35495,
      37.19961,
      38.56898,
      39.66775,
      40.57167,
      41.32285,
      41.95185,
      42.48206,
      42.93322,
      43.3214,
      43.65819,
      43.95282
    ],
    [
      32.83389,
      35.77923,
      37.62565,
      38.99847,
      40.10153,
      41.01031,
      41.76631,
      42.39988,
      42.93439,
      43.38967,
      43.78163,
      44.12182,
      44.41958,
    ],
    [
      33.60502,
      36.48819,
      38.33754,
      39.71613,
      40.82636,
      41.74325,
      42.5073,
      43.14851,
      43.69022,
      44.15237,
      44.55065,
      44.89654,
      45.19953,
    ],
    [
      34.4618,
      37.2759,
      39.1285,
      40.5135,
      41.6317,
      42.5576,
      43.3306,
      43.9803,
      44.53,
      44.9998,
      45.4051,
      45.7573,
      46.0661,
    ],
    [
      35.31858,
      38.06361,
      39.91946,
      41.31087,
      42.43704,
      43.37195,
      44.1539,
      44.81209,
      45.36978,
      45.84723,
      46.25955,
      46.61806,
      46.93267,
    ],
    [
      36.08971,
      38.77257,
      40.63135,
      42.02853,
      43.16187,
      44.10489,
      44.89489,
      45.56072,
      46.12561,
      46.60993,
      47.02857,
      47.39278,
      47.71262,
    ],
    [
      36.55119,
      39.19685,
      41.05739,
      42.45802,
      43.59565,
      44.54353,
      45.33835,
      46.00875,
      46.57794,
      47.06638,
      47.4888,
      47.85641,
      48.17938,
    ],
    [
      37.0023239,
      39.6116079,
      41.4738623,
      42.8778679,
      44.0196943,
      44.9723182,
      45.771846,
      46.4467152,
      47.0201176,
      47.5125888,
      47.9387046,
      48.3096422,
      48.6356671,
    ]
  ];

I need to divide these values by 2.54

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

void main() {
  List boyHeadCircumferenceData = [...];
  
  convertCircumferenceToInches(boyHeadCircumferenceData);
  
  for(int i = 0; i < boyHeadCircumferenceData.length; i++){
    print("$i ${boyHeadCircumferenceData[i]}");
  }
}

void convertCircumferenceToInches(List circumferenceData) {
  for (int i = 0; i < circumferenceData.length; i++) {
    for (int j = 0; j < circumferenceData[i].length; j++) {
      circumferenceData[i][j] /= 2.54;
    }
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading